[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master d0e9b88 1/2: xref-matches-in-files: Decrease per match and per gr
From: |
Dmitry Gutov |
Subject: |
master d0e9b88 1/2: xref-matches-in-files: Decrease per match and per group overhead |
Date: |
Thu, 23 Sep 2021 13:37:37 -0400 (EDT) |
branch: master
commit d0e9b88bf744ad956c8be345789e3d8acfe69def
Author: Dmitry Gutov <dgutov@yandex.ru>
Commit: Dmitry Gutov <dgutov@yandex.ru>
xref-matches-in-files: Decrease per match and per group overhead
* lisp/progmodes/xref.el (xref-search-program-alist):
Add '--null' argument for slightly faster parsing and probably
better behavior with weirder file names.
(xref--alistify): Don't accept TEST argument, use 'assoc' instead
of 'cl-assoc', use a tash table during sorting (bug#50733).
---
lisp/progmodes/xref.el | 24 +++++++++++-------------
1 file changed, 11 insertions(+), 13 deletions(-)
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index 772e664..88ee1d5 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -307,20 +307,19 @@ recognize and then delegate the work to an external
process."
;;; misc utilities
-(defun xref--alistify (list key test)
+(defun xref--alistify (list key)
"Partition the elements of LIST into an alist.
-KEY extracts the key from an element and TEST is used to compare
-keys."
- (let ((alist '()))
+KEY extracts the key from an element."
+ (let ((table (make-hash-table :test #'equal)))
(dolist (e list)
(let* ((k (funcall key e))
- (probe (cl-assoc k alist :test test)))
+ (probe (gethash k table)))
(if probe
- (setcdr probe (cons e (cdr probe)))
- (push (cons k (list e)) alist))))
+ (puthash k (cons e probe) table)
+ (puthash k (list e) table))))
;; Put them back in order.
- (cl-loop for (key . value) in (reverse alist)
- collect (cons key (reverse value)))))
+ (cl-loop for key being hash-keys of table using (hash-values value)
+ collect (cons key (nreverse value)))))
(defun xref--insert-propertized (props &rest strings)
"Insert STRINGS with text properties PROPS."
@@ -1046,8 +1045,7 @@ Return an alist of the form ((GROUP . (XREF ...)) ...)."
(let* ((alist
(xref--alistify xrefs
(lambda (x)
- (xref-location-group (xref-item-location x)))
- #'equal))
+ (xref-location-group (xref-item-location x)))))
(project (and
(eq xref-file-name-display 'project-relative)
(project-current)))
@@ -1622,11 +1620,11 @@ IGNORES is a list of glob patterns for files to ignore."
'((grep
.
;; '-s' because 'git ls-files' can output broken symlinks.
- "xargs -0 grep <C> -snHE -e <R>")
+ "xargs -0 grep <C> --null -snHE -e <R>")
(ripgrep
.
;; '!*/' is there to filter out dirs (e.g. submodules).
- "xargs -0 rg <C> -nH --no-messages -g '!*/' -e <R>"
+ "xargs -0 rg <C> --null -nH --no-messages -g '!*/' -e <R>"
))
"Associative list mapping program identifiers to command templates.