From: Dmitry Gutov Date: Thu, 23 Sep 2021 16:08:36 +0000 (+0300) Subject: xref-matches-in-files: Decrease per match and per group overhead X-Git-Tag: emacs-28.0.90~711 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=d0e9b88bf744ad956c8be345789e3d8acfe69def;p=emacs.git 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). --- diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index 772e6646d95..88ee1d5d16f 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 -snHE -e ") + "xargs -0 grep --null -snHE -e ") (ripgrep . ;; '!*/' is there to filter out dirs (e.g. submodules). - "xargs -0 rg -nH --no-messages -g '!*/' -e " + "xargs -0 rg --null -nH --no-messages -g '!*/' -e " )) "Associative list mapping program identifiers to command templates.