* 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
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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.