Use skip-syntax-forward instead of re-search-forward

Time needed to do 1000 fontifications of rainbow-delimiters.el:
Before: 3.01 s
After: 2.25 s
master
Fanael Linithien 11 years ago
parent c1149daac0
commit d007f2d797
  1. 14
      rainbow-delimiters.el

@ -215,9 +215,6 @@ Returns t if char at loc meets one of the following conditions:
(t
nil))))
(defconst rainbow-delimiters--delim-regex "\\s(\\|\\s)"
"Regex matching all opening and closing delimiters the mode highlights.")
;; Main function called by font-lock.
(defun rainbow-delimiters--propertize (end)
"Highlight delimiters in region between point and END.
@ -226,12 +223,15 @@ Used by font-lock for dynamic highlighting."
(let* ((inhibit-point-motion-hooks t)
(last-ppss-pos (point))
(ppss (syntax-ppss)))
(while (re-search-forward rainbow-delimiters--delim-regex end t)
(let* ((delim-pos (match-beginning 0))
(while (> end (progn (skip-syntax-forward "^()" end)
(point)))
(let* ((delim-pos (point))
(delim-syntax (syntax-after delim-pos)))
(setq ppss (save-excursion
(parse-partial-sexp last-ppss-pos delim-pos nil nil ppss)))
(setq ppss (parse-partial-sexp last-ppss-pos delim-pos nil nil ppss))
(setq last-ppss-pos delim-pos)
;; `skip-syntax-forward' leaves the point at the delimiter, move past
;; it.
(forward-char)
(let ((delim-syntax-code (car delim-syntax)))
(cond
((rainbow-delimiters--char-ineligible-p delim-pos ppss delim-syntax-code)

Loading…
Cancel
Save