GNU bug report logs -
#17514
24.3.91; enhancement: byte-optimize looking-at-p
Previous Next
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.
Full log
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
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
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.