branch: externals/gtags-mode commit a83bf3898d1e489d45071739d33ea696d884c142 Author: Jimmy Aguilar Mena <kratsbinov...@gmail.com> Commit: Jimmy Aguilar Mena <kratsbinov...@gmail.com>
Optimize project-files When project-files-relative-names is set we can avoid passing throw mapcar+mapcan+expand-file-name Specifically expand-file-name adds 2x overhead when using tramp due to tramp-file-name-handler. This is very noticeable in projects with ~10^5 files where times are ~40 secs. This optimization reduces the time to ~15-20 secs This commit adds extra code and a few extra potential optimizations. --- gtags-mode.el | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/gtags-mode.el b/gtags-mode.el index 92b75e6945..89d6d29957 100644 --- a/gtags-mode.el +++ b/gtags-mode.el @@ -5,7 +5,7 @@ ;; Author: Jimmy Aguilar Mena ;; URL: https://github.com/Ergus/gtags-mode ;; Keywords: xref, project, imenu, gtags, global -;; Version: 1.8.6 +;; Version: 1.8.7 ;; Package-Requires: ((emacs "28")) ;; This program is free software: you can redistribute it and/or modify @@ -379,19 +379,22 @@ Return as a list of xref location objects." (cl-defmethod project-files ((project (head :gtagsroot)) &optional dirs) "List files inside all the PROJECT or in DIRS if specified." - (let* ((root (project-root project)) - (default-directory root) - (results - (mapcan - (lambda (dir) - (when (string-prefix-p root dir) - (mapcar (lambda (file) - (expand-file-name file root)) - (gtags-mode--exec-sync - "--path-style=through" "--path" - (string-remove-prefix root dir))))) - (or dirs `(,root))))) - (if (> (length dirs) 1) (delete-dups results) results))) + (let* ((default-directory (project-root project)) + (dirs (or (delete-dups dirs) `(,default-directory))) + (results (if project-files-relative-names + (gtags-mode--exec-sync + "--path-style=relative" "--path" + (string-remove-prefix default-directory (car dirs))) + (mapcan + (lambda (dir) + (when (string-prefix-p default-directory dir) + (mapcar (lambda (file) + (expand-file-name file default-directory)) + (gtags-mode--exec-sync + "--path-style=through" "--path" + (string-remove-prefix default-directory dir))))) + dirs)))) + (if (length> dirs 1) (delete-dups results) results))) (cl-defmethod project-buffers ((project (head :gtagsroot))) "Return the list of all live buffers that belong to PROJECT."