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

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

[nongnu] elpa/go-mode 4aeb058 078/495: add cache to go-previous-line-has


From: ELPA Syncer
Subject: [nongnu] elpa/go-mode 4aeb058 078/495: add cache to go-previous-line-has-dangling-op-p
Date: Sat, 7 Aug 2021 09:04:47 -0400 (EDT)

branch: elpa/go-mode
commit 4aeb058e1830855f7f6ae5bbc97cdbf69e985a13
Author: Dominik Honnef <dominikh@fork-bomb.org>
Commit: Dominik Honnef <dominikh@fork-bomb.org>

    add cache to go-previous-line-has-dangling-op-p
---
 go-mode.el | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/go-mode.el b/go-mode.el
index 3713eb2..a9130e3 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -27,6 +27,7 @@
 (defconst go-constants '("nil" "true" "false" "iota"))
 (defconst go-type-name-regexp (concat "\\(?:[*(]\\)*\\(?:" 
go-identifier-regexp "\\.\\)?\\(" go-identifier-regexp "\\)"))
 
+(defvar go-dangling-cache)
 
 (defgroup go nil
   "Major mode for editing Go code"
@@ -156,10 +157,14 @@ some syntax analysis.")
     (/= start-pos (point))))
 
 (defun go-previous-line-has-dangling-op-p ()
-  (save-excursion
-    (beginning-of-line)
-    (go--backward-irrelevant t)
-    (looking-back go-dangling-operators-regexp)))
+  (let* ((cur-line (count-lines (point-min) (point)))
+        (val (gethash cur-line go-dangling-cache 'nope)))
+    (if (equal val 'nope)
+      (save-excursion
+        (beginning-of-line)
+        (go--backward-irrelevant t)
+        (puthash cur-line (looking-back go-dangling-operators-regexp) 
go-dangling-cache))
+      val)))
 
 (defun go-goto-opening-parenthesis (&optional char)
   (let ((start-nesting (go-paren-level)) group)
@@ -280,6 +285,8 @@ functions, and some types.  It also provides indentation 
that is
 
   (set (make-local-variable 'beginning-of-defun-function) 
'go-beginning-of-defun)
   (set (make-local-variable 'end-of-defun-function) 'go-end-of-defun)
+  (set (make-local-variable 'go-dangling-cache) #s(hash-table test eql))
+  (add-to-list 'before-change-functions (lambda (x y) (setq go-dangling-cache 
#s(hash-table test eql))))
 
 
   (setq imenu-generic-expression



reply via email to

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