branch: elpa/go-mode
commit fb1272ce3154ef241a368502c6c1b7772d3929d9
Author: Muir Manders <[email protected]>
Commit: Peter Sanford <[email protected]>
indent: fix performance in giant comments
The recently added "case" comment logic was performing poorly on giant
comments (e.g. golang/src/cmd/go/alldocs.go). It was spending a long
time searching forwards and backwards through all the comments to see
if it was attached to a "case" statement. Note that this issue only
started happening after the previous commit. Before, we were hitting
an elisp max depth exceeded error due to the recursive nature of
go--backward-irrelevant. go-previous-line-has-dangling-op-p no longer
calls go--backward-irrelevant so the performance issue became
noticeable. I made two tweaks to speed this up:
1. Assume we aren't above a case statement if comment's current indent
is 0. This completely avoids all the work for giant doc.go style
comments. This will mess things up a little in cases like:
{
switch foo {
// hi
case 123:
}
}
where the "hi" comment (with current indent of 0) will first get
indented beyond the case statement (but if you indent again, it will
get aligned with the case). I imagine this to be very uncommon, so a
worthwhile tradeoff.
2. Make go-in-comment-p the final "cond" clause. This is a relatively
expensive check, so this will speed up other cases of big comments
not covered by 1.
Closes: #290 [via git-merge-pr]
---
go-mode.el | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/go-mode.el b/go-mode.el
index 348d986..3bbe162 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -893,7 +893,10 @@ Return non-nil if point changed lines."
"Return non-nil if looking at a comment attached to a case statement.
INDENT is the normal indent of this line, i.e. that of the case body."
- (when (looking-at go--comment-start-regexp)
+ (when (and
+ (> (current-indentation) 0)
+ (looking-at go--comment-start-regexp))
+
(let (switch-before
case-after
has-case-aligned-preceding-comment)
@@ -903,14 +906,14 @@ INDENT is the normal indent of this line, i.e. that of
the case body."
(while (and
(zerop (forward-line -1))
(cond
- ((go-in-comment-p))
-
((looking-at "^[[:space:]]*$"))
((looking-at go--comment-start-regexp)
(when (= (current-indentation) (- indent tab-width))
(setq has-case-aligned-preceding-comment t))
- t))))
+ t)
+
+ ((go-in-comment-p)))))
;; Record if a switch (or select) precedes us.
(setq switch-before (looking-at
"^[[:space:]]*\\(switch\\|select\\)[[:space:]]")))
@@ -920,9 +923,9 @@ INDENT is the normal indent of this line, i.e. that of the
case body."
(while (and
(zerop (forward-line 1))
(or
- (go-in-comment-p)
(looking-at go--comment-start-regexp)
- (looking-at "^[[:space:]]*$"))))
+ (looking-at "^[[:space:]]*$")
+ (go-in-comment-p))))
(setq case-after (looking-at go--case-or-default-regexp)))