unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#17514: 24.3.91; enhancement: byte-optimize looking-at-p
@ 2014-05-16 22:07 Shigeru Fukaya
  2014-05-16 22:42 ` Stefan Monnier
  0 siblings, 1 reply; 3+ messages in thread
From: Shigeru Fukaya @ 2014-05-16 22:07 UTC (permalink / raw)
  To: 17514

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






^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#17514: 24.3.91; enhancement: byte-optimize looking-at-p
  2014-05-16 22:07 bug#17514: 24.3.91; enhancement: byte-optimize looking-at-p Shigeru Fukaya
@ 2014-05-16 22:42 ` Stefan Monnier
  2014-05-17 13:06   ` Shigeru Fukaya
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Monnier @ 2014-05-16 22:42 UTC (permalink / raw)
  To: Shigeru Fukaya; +Cc: 17514

> 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





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#17514: 24.3.91; enhancement: byte-optimize looking-at-p
  2014-05-16 22:42 ` Stefan Monnier
@ 2014-05-17 13:06   ` Shigeru Fukaya
  0 siblings, 0 replies; 3+ messages in thread
From: Shigeru Fukaya @ 2014-05-17 13:06 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 17514

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





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-05-17 13:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-16 22:07 bug#17514: 24.3.91; enhancement: byte-optimize looking-at-p Shigeru Fukaya
2014-05-16 22:42 ` Stefan Monnier
2014-05-17 13:06   ` Shigeru Fukaya

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).