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

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

[elpa] externals/trie e1be744 030/111: Bug-fix in trie--do-wildcard-sear


From: Stefan Monnier
Subject: [elpa] externals/trie e1be744 030/111: Bug-fix in trie--do-wildcard-search
Date: Mon, 14 Dec 2020 11:35:14 -0500 (EST)

branch: externals/trie
commit e1be744f7e5fdd64ca35a6516df00f4142da06c7
Author: Toby Cubitt <toby-predictive@dr-qubit.org>
Commit: tsc25 <toby-predictive@dr-qubit.org>

    Bug-fix in trie--do-wildcard-search
---
 trie.el | 44 +++++++++++++++++++++++++++-----------------
 1 file changed, 27 insertions(+), 17 deletions(-)

diff --git a/trie.el b/trie.el
index 642af33..34df39a 100644
--- a/trie.el
+++ b/trie.el
@@ -1681,16 +1681,17 @@ wildcards will be particularly slow."
 
   ;; if pattern is null, accumulate data from current node
   (if (null pattern)
-      (unless (null group-stack)
-       (error "Syntax error in trie wildcard pattern: missing \")\""))
-      (when (setq node (trie--find-data-node node lookupfun))
-       (setq groups
-             (sort groups
-                   (lambda (a b)
-                     (or (< (car a) (car b))
-                         (and (= (car a) (car b))
-                              (> (cdr a) (cdr b)))))))
-       (funcall accumulator node (if groups (cons seq groups) seq)))
+      (progn
+       (unless (null group-stack)
+         (error "Syntax error in trie wildcard pattern: missing \")\""))
+       (when (setq node (trie--find-data-node node lookupfun))
+         (setq groups
+               (sort groups
+                     (lambda (a b)
+                       (or (< (car a) (car b))
+                           (and (= (car a) (car b))
+                                (> (cdr a) (cdr b)))))))
+         (funcall accumulator node (if groups (cons seq groups) seq))))
 
     ;; otherwise, extract first pattern element and act on it
     (setq pattern (trie--wildcard-parse-pattern pattern))
@@ -1730,11 +1731,19 @@ wildcards will be particularly slow."
 
        ;; terminal *: accumulate everything below current node
        ((and (null pattern) (trie--wildcard-*-p el))
-       (trie--mapc accumulator mapfun node seq
-                   (if maxnum reverse (not reverse))))
-
-       ;; terminal * then ): accumulate everything below current node and
-       ;;                    close group(s)
+       (unless (null group-stack)
+         (error "Syntax error in trie wildcard pattern: missing \")\""))
+       (let ((grps (sort (copy-sequence groups)
+                         (lambda (a b)
+                           (or (< (car a) (car b))
+                               (and (= (car a) (car b))
+                                    (> (cdr a) (cdr b))))))))
+         (trie--mapc
+          (lambda (node seq) (funcall accumulator node (cons seq grps)))
+          mapfun node seq (if maxnum reverse (not reverse)))))
+
+       ;; terminal * and ): accumulate everything below current node and
+       ;;                   close group(s)
        ((and (trie--wildcard-*-p el)
             (catch 'not-group
               (dolist (el pattern)
@@ -1745,10 +1754,11 @@ wildcards will be particularly slow."
           (let ((grp-stack group-stack)
                 (grps (copy-sequence groups))
                 (pat pattern))
-            (dotimes (i (trie--wildcard-group-count el))
+            (while pat
               (if (null grp-stack)
                   (error "Syntax error in trie wildcard pattern: missing 
\"(\"")
-                (push (cons (pop grp-stack) idx) grps)))
+                (push (cons (pop grp-stack) idx) grps)
+                (setq pat (cdr pat))))
             (unless (null grp-stack)
               (error "Syntax error in trie wildcard pattern: missing \")\""))
             (setq grps



reply via email to

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