emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[nongnu] elpa/go-mode e20a54a 426/495: Speed up go-previous-line-has-dan


From: ELPA Syncer
Subject: [nongnu] elpa/go-mode e20a54a 426/495: Speed up go-previous-line-has-dangling-op-p
Date: Sat, 7 Aug 2021 09:06:01 -0400 (EDT)

branch: elpa/go-mode
commit e20a54a6949a70acd37b228be5cd12d3c36595bb
Author: Muir Manders <muir@retailnext.net>
Commit: Peter Sanford <psanford@sanford.io>

    Speed up go-previous-line-has-dangling-op-p
    
    Don't call line-number-at-pos since that starts at the beginning of
    the buffer and counts lines one at a time. Instead we now cache
    danglingness by the position of the start of the line instead of the
    line number. We might not need the cache anymore (didn't check).
    
    We also store and return the position of the line with the dangling
    operator as the hash value (will use in later commit).
---
 go-mode.el | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/go-mode.el b/go-mode.el
index 361c862..009f349 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -537,17 +537,22 @@ STOP-AT-STRING is not true, over strings."
          (point-min))))
 
 (defun go-previous-line-has-dangling-op-p ()
-  "Return non-nil if the current line is a continuation line."
-  (let* ((cur-line (line-number-at-pos))
-         (val (gethash cur-line go-dangling-cache 'nope)))
-    (if (or (go--buffer-narrowed-p) (equal val 'nope))
-        (save-excursion
-          (beginning-of-line)
-          (go--backward-irrelevant t)
-          (setq val (looking-back go-dangling-operators-regexp
-                                  (- (point) 
go--max-dangling-operator-length)))
-          (if (not (go--buffer-narrowed-p))
-              (puthash cur-line val go-dangling-cache))))
+  "Return non-nil if the current line is a continuation line.
+
+The returned value is the beginning of the line with the dangling operator."
+  (let* ((line-begin (line-beginning-position))
+         (val (gethash line-begin go-dangling-cache 'nope)))
+    (when (or (go--buffer-narrowed-p) (equal val 'nope))
+      (save-excursion
+        (beginning-of-line)
+        (go--backward-irrelevant t)
+        (if (looking-back go-dangling-operators-regexp
+                          (- (point) go--max-dangling-operator-length))
+            (setq val (line-beginning-position))
+          (setq val nil))
+
+        (if (not (go--buffer-narrowed-p))
+            (puthash line-begin val go-dangling-cache))))
     val))
 
 (defun go--at-function-definition ()



reply via email to

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