emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master b0b483d: Use integers for syntax-pps-stats


From: Paul Eggert
Subject: [Emacs-diffs] master b0b483d: Use integers for syntax-pps-stats
Date: Sun, 6 Jan 2019 14:15:45 -0500 (EST)

branch: master
commit b0b483d714e87ee0a4572f9c541514a1ac1a8226
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>

    Use integers for syntax-pps-stats
    
    * lisp/emacs-lisp/syntax.el (syntax-ppss-stats):
    Use integers, not floating-point, for stats, now that integers are
    unbounded.  Almost always these should be fixnums.  Add 1 to last
    slot’s car so that this addition need not be done at runtime.
    (syntax-pps-stats, syntax-ppss): Use integers for calculations.
    (syntax-ppss--update-stats): New convenience function.
    (syntax-ppss): Use it.
---
 lisp/emacs-lisp/syntax.el | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/lisp/emacs-lisp/syntax.el b/lisp/emacs-lisp/syntax.el
index 0bc90e5..11cab1d 100644
--- a/lisp/emacs-lisp/syntax.el
+++ b/lisp/emacs-lisp/syntax.el
@@ -434,14 +434,20 @@ These are valid when the buffer has no restriction.")
        (setcdr cell cache)))
     ))
 
+;;; FIXME: Explain this variable.  Currently only its last (5th) slot is used.
+;;; Perhaps the other slots should be removed?
 (defvar syntax-ppss-stats
-  [(0 . 0.0) (0 . 0.0) (0 . 0.0) (0 . 0.0) (0 . 0.0) (1 . 2500.0)])
+  [(0 . 0) (0 . 0) (0 . 0) (0 . 0) (0 . 0) (2 . 2500)])
 (defun syntax-ppss-stats ()
   (mapcar (lambda (x)
            (condition-case nil
-               (cons (car x) (truncate (/ (cdr x) (car x))))
+               (cons (car x) (/ (cdr x) (car x)))
              (error nil)))
          syntax-ppss-stats))
+(defun syntax-ppss--update-stats (i old new)
+  (let ((pair (aref syntax-ppss-stats i)))
+    (cl-incf (car pair))
+    (cl-incf (cdr pair) (- new old))))
 
 (defvar-local syntax-ppss-table nil
   "Syntax-table to use during `syntax-ppss', if any.")
@@ -486,11 +492,10 @@ running the hook."
        (if (and old-pos (< (- pos old-pos)
                            ;; The time to use syntax-begin-function and
                            ;; find PPSS is assumed to be about 2 * distance.
-                           (* 2 (/ (cdr (aref syntax-ppss-stats 5))
-                                   (1+ (car (aref syntax-ppss-stats 5)))))))
+                           (let ((pair (aref syntax-ppss-stats 5)))
+                             (/ (* 2 (cdr pair)) (car pair)))))
            (progn
-             (cl-incf (car (aref syntax-ppss-stats 0)))
-             (cl-incf (cdr (aref syntax-ppss-stats 0)) (- pos old-pos))
+             (syntax-ppss--update-stats 0 old-pos pos)
              (parse-partial-sexp old-pos pos nil nil old-ppss))
 
          (cond
@@ -506,8 +511,7 @@ running the hook."
                 (setq pt-min (or (syntax-ppss-toplevel-pos old-ppss)
                                  (nth 2 old-ppss)))
                 (<= pt-min pos) (< (- pos pt-min) syntax-ppss-max-span))
-           (cl-incf (car (aref syntax-ppss-stats 1)))
-           (cl-incf (cdr (aref syntax-ppss-stats 1)) (- pos pt-min))
+           (syntax-ppss--update-stats 1 pt-min pos)
            (setq ppss (parse-partial-sexp pt-min pos)))
           ;; The OLD-* data can't be used.  Consult the cache.
           (t
@@ -535,8 +539,7 @@ running the hook."
              ;; Use the best of OLD-POS and CACHE.
              (if (or (not old-pos) (< old-pos pt-min))
                  (setq pt-best pt-min ppss-best ppss)
-               (cl-incf (car (aref syntax-ppss-stats 4)))
-               (cl-incf (cdr (aref syntax-ppss-stats 4)) (- pos old-pos))
+               (syntax-ppss--update-stats 4 old-pos pos)
                (setq pt-best old-pos ppss-best old-ppss))
 
              ;; Use the `syntax-begin-function' if available.
@@ -556,21 +559,18 @@ running the hook."
                         (not (memq (get-text-property (point) 'face)
                                    '(font-lock-string-face font-lock-doc-face
                                      font-lock-comment-face))))
-               (cl-incf (car (aref syntax-ppss-stats 5)))
-               (cl-incf (cdr (aref syntax-ppss-stats 5)) (- pos (point)))
+               (syntax-ppss--update-stats 5 (point) pos)
                (setq pt-best (point) ppss-best nil))
 
              (cond
               ;; Quick case when we found a nearby pos.
               ((< (- pos pt-best) syntax-ppss-max-span)
-               (cl-incf (car (aref syntax-ppss-stats 2)))
-               (cl-incf (cdr (aref syntax-ppss-stats 2)) (- pos pt-best))
+               (syntax-ppss--update-stats 2 pt-best pos)
                (setq ppss (parse-partial-sexp pt-best pos nil nil ppss-best)))
               ;; Slow case: compute the state from some known position and
               ;; populate the cache so we won't need to do it again soon.
               (t
-               (cl-incf (car (aref syntax-ppss-stats 3)))
-               (cl-incf (cdr (aref syntax-ppss-stats 3)) (- pos pt-min))
+               (syntax-ppss--update-stats 3 pt-min pos)
 
                ;; If `pt-min' is too far, add a few intermediate entries.
                (while (> (- pos pt-min) (* 2 syntax-ppss-max-span))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]