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

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

[nongnu] elpa/treesit-fold 8f1f182b40 307/417: perf: Speed up count matc


From: ELPA Syncer
Subject: [nongnu] elpa/treesit-fold 8f1f182b40 307/417: perf: Speed up count matches (#88)
Date: Mon, 1 Jul 2024 10:02:47 -0400 (EDT)

branch: elpa/treesit-fold
commit 8f1f182b40a4168352b60132bf9c9b9f8a5549c9
Author: Jen-Chieh Shen <jcs090218@gmail.com>
Commit: GitHub <noreply@github.com>

    perf: Speed up count matches (#88)
    
    * perf: Speed up count matches
    
    * fix docstr
---
 ts-fold-util.el | 6 ++++++
 ts-fold.el      | 4 ++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/ts-fold-util.el b/ts-fold-util.el
index 7704f6bab1..d4588c769b 100644
--- a/ts-fold-util.el
+++ b/ts-fold-util.el
@@ -33,6 +33,12 @@
   "Convert OBJ to string."
   (format "%s" obj))
 
+(defun ts-fold--count-matches (pattern str)
+  "Count occurrences of PATTERN in STR.
+
+Like function `s-count-matches' but faster."
+  (max 0 (1- (length (split-string str pattern)))))
+
 ;;
 ;; (@* "Cons" )
 ;;
diff --git a/ts-fold.el b/ts-fold.el
index cddd2f3c9a..d35407adf7 100644
--- a/ts-fold.el
+++ b/ts-fold.el
@@ -450,12 +450,12 @@ in backward direction."
     (while (and iter-node (not break))
       (setq text (tsc-node-text iter-node)
             line (car (tsc-node-start-point iter-node))
-            line-range (1+ (s-count-matches "\n" text))
+            line-range (1+ (ts-fold--count-matches "\n" text))
             max-line-range (max line-range last-line-range))
       (if (and (ts-fold--in-range-p line (- last-line max-line-range) (+ 
last-line max-line-range))
                (string-prefix-p prefix text))
           (setq last-node iter-node last-line line
-                last-line-range (1+ (s-count-matches "\n" text)))
+                last-line-range (1+ (ts-fold--count-matches "\n" text)))
         (setq break t))
       (setq iter-node (ts-fold--next-prev-node-skip-newline iter-node next)))
     last-node))



reply via email to

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