GNU bug report logs - #17514
24.3.91; enhancement: byte-optimize looking-at-p

Previous Next

Package: emacs;

Reported by: Shigeru Fukaya <shigeru.fukaya <at> gmail.com>

Date: Fri, 16 May 2014 22:09:02 UTC

Severity: wishlist

Tags: patch, wontfix

Found in version 24.3.91

Done: Glenn Morris <rgm <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 17514 in the body.
You can then email your comments to 17514 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#17514; Package emacs. (Fri, 16 May 2014 22:09:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Shigeru Fukaya <shigeru.fukaya <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 16 May 2014 22:09:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Shigeru Fukaya <shigeru.fukaya <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.3.91; enhancement: byte-optimize looking-at-p
Date: Sat, 17 May 2014 07:07:43 +0900
looking-at-p is now a core function.
I think (looking-at-p "a") can be safely optimized to
(eq (following-char) ?a).
I found there are 8 such codes in the current trunk, and some more possibly
changable to looking-at-p from lookin-at.

I made an experimental byte-optimization code.


(defun byte-optimize-looking-at-p (form)
  (or (if (and (= (length form) 2)
               (stringp (nth 1 form)))
          (if (equal (nth 1 form) "")
              ;; (looking-at-p "")
              t
            (let ((c (byte-optimize-regexp-to-char (nth 1 form))))
              (if c
                  (list 'eq (list 'following-char) c)))))
      ;; fallback to original defsubst expansion
      (byte-compile-inline-expand form)))

(defun byte-optimize-regexp-to-char (regexp)
  (let* ((special '(?\[ ?* ?. ?\\ ?? ?+ ?^ ?$))
         (len (length regexp))
         (c (aref regexp (1- len))))
    (cond
     ;; don't accept '\0'.
     ;; as (following-char) at eob returns 0.
     ((eq c ?\0) nil)
     ;; "a" -> ?a
     ((= len 1) (unless (memq c special) c))
     ;; "\\." -> ?.  (only special characters, so far)
     ((= len 2) (when (and (eq (aref regexp 0) ?\\)
                           (memq c special))
                  c)))))

(put 'looking-at-p 'byte-optimizer 'byte-optimize-looking-at-p)
(put 'looking-at-p 'side-effect-free t)


-- Shigeru





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#17514; Package emacs. (Fri, 16 May 2014 22:44:02 GMT) Full text and rfc822 format available.

Message #8 received at 17514 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Shigeru Fukaya <shigeru.fukaya <at> gmail.com>
Cc: 17514 <at> debbugs.gnu.org
Subject: Re: bug#17514: 24.3.91; enhancement: byte-optimize looking-at-p
Date: Fri, 16 May 2014 18:42:58 -0400
> I think (looking-at-p "a") can be safely optimized to
> (eq (following-char) ?a).
> I found there are 8 such codes in the current trunk, and some more possibly
> changable to looking-at-p from lookin-at.

I don't think it's worth the trouble.  Better just rewrite those
8 occurrences.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#17514; Package emacs. (Sat, 17 May 2014 13:07:02 GMT) Full text and rfc822 format available.

Message #11 received at 17514 <at> debbugs.gnu.org (full text, mbox):

From: Shigeru Fukaya <shigeru.fukaya <at> gmail.com>
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: 17514 <at> debbugs.gnu.org
Subject: Re: bug#17514: 24.3.91; enhancement: byte-optimize looking-at-p
Date: Sat, 17 May 2014 22:06:23 +0900
I should concentrate on explicit bugs only, maybe.

Thank you.


>> I think (looking-at-p "a") can be safely optimized to
>> (eq (following-char) ?a).
>> I found there are 8 such codes in the current trunk, and some more possibly
>> changable to looking-at-p from lookin-at.
>
>I don't think it's worth the trouble.  Better just rewrite those
>8 occurrences.
>
>
>        Stefan




Added tag(s) wontfix. Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Sun, 18 May 2014 16:55:02 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 17514 <at> debbugs.gnu.org and Shigeru Fukaya <shigeru.fukaya <at> gmail.com> Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Sun, 18 May 2014 16:55:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 16 Jun 2014 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 11 years and 7 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.