From 7602b225487da39ccc639261f426844af1d52ec7 Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Mon, 7 Mar 2022 22:01:11 -0800 Subject: [PATCH] Cache abbreviated home directory for Tramp This improves performance when there are many entries in 'directory-abbrev-alist'. * lisp/net/tramp.el (tramp-handle-abbreviate-file-name): Cache abbreviated home directory. --- lisp/net/tramp.el | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 5bf6a54020..560ed1f8ed 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -3361,17 +3361,19 @@ tramp-handle-abbreviate-file-name (vec (tramp-dissect-file-name filename)) (tramp-tolerate-tilde t) (home-dir - (if (let ((non-essential t)) (tramp-connectable-p vec)) - ;; If a connection has already been established, get the - ;; home directory. - (tramp-get-home-directory vec) - ;; Otherwise, just use the cached value. - (tramp-get-connection-property vec "~" nil)))) - (when home-dir - (setq home-dir - (tramp-compat-funcall - 'directory-abbrev-apply - (tramp-make-tramp-file-name vec home-dir)))) + (catch 'no-home-dir + (with-tramp-connection-property vec "abbr-home-directory" + (tramp-compat-funcall + 'directory-abbrev-apply + (tramp-make-tramp-file-name + vec + (if (let ((non-essential t)) (tramp-connectable-p vec)) + ;; If a connection has already been established, get the + ;; home directory. + (tramp-get-home-directory vec) + ;; Otherwise, just use the cached value. + (or (tramp-get-connection-property vec "~" nil) + (throw 'no-home-dir))))))))) ;; If any elt of `directory-abbrev-alist' matches this name, ;; abbreviate accordingly. (setq filename (tramp-compat-funcall 'directory-abbrev-apply filename)) -- 2.25.1