]> git.eshelyaron.com Git - emacs.git/commitdiff
Speed up glob matching 2x
authorJoão Távora <joaotavora@gmail.com>
Mon, 1 Feb 2021 17:23:07 +0000 (17:23 +0000)
committerJoão Távora <joaotavora@gmail.com>
Mon, 1 Feb 2021 17:52:29 +0000 (17:52 +0000)
with-temp-buffer was taking a lot of time, presumably because it kills
the buffer.  Since emacs is single-threaded, we can safely reuse a
single buffer.

* eglot.el (eglot--glob-parse): Simplify grammar.
(eglot--glob-compile): Don't with-temp-buffer.

GitHub-reference: per https://github.com/joaotavora/eglot/issues/602

lisp/progmodes/eglot.el

index 44648ae41b4d3c5e1003d953f5132e799ea20414..50fb695319a5ccb6ab964489dc044b4c269b8b04 100644 (file)
@@ -2672,10 +2672,9 @@ at point.  With prefix argument, prompt for ACTION-KIND."
      with grammar = '((:**      "\\*\\*/?"              eglot--glob-emit-**)
                       (:*       "\\*"                   eglot--glob-emit-*)
                       (:?       "\\?"                   eglot--glob-emit-?)
-                      (:/       "/"                     eglot--glob-emit-self)
                       (:{}      "{[^][/*{}]+}"          eglot--glob-emit-{})
                       (:range   "\\[\\^?[^][/,*{}]+\\]" eglot--glob-emit-range)
-                      (:literal "[^][/,*?{}]+"          eglot--glob-emit-self))
+                      (:literal "[^][,*?{}]+"           eglot--glob-emit-self))
      until (eobp)
      collect (cl-loop
               for (_token regexp emitter) in grammar
@@ -2687,7 +2686,8 @@ at point.  With prefix argument, prompt for ACTION-KIND."
   "Convert GLOB into Elisp function.  Maybe BYTE-COMPILE it.
 If NOERROR, return predicate, else erroring function."
   (let* ((states (eglot--glob-parse glob))
-         (body `(with-temp-buffer
+         (body `(with-current-buffer (get-buffer-create " *eglot-glob-matcher*")
+                  (erase-buffer)
                   (save-excursion (insert string))
                   (cl-labels ,(cl-loop for (this that) on states
                                        for (self emit text) = this