From 0547e23411755e3366eacf5d3385025df8833d9b Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 18 Dec 2012 11:32:58 +0100 Subject: [PATCH] Avoid calls to stat() in find_matches Instead of stating every directory to check if its realpath is the current directory, only do so for any potential matches. --- bin/autojump | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bin/autojump b/bin/autojump index 91ef235..c2f3a22 100755 --- a/bin/autojump +++ b/bin/autojump @@ -368,10 +368,6 @@ def find_matches(db, patterns, max_matches=1, ignore_case=False, fuzzy=False): return [] for path, _ in dirs: - # avoid jumping to current directory - if current_dir == decode(os.path.realpath(path)) : - continue - found, tmp = True, path for n, p in enumerate(patterns): # for single/last pattern, only check end of path @@ -382,6 +378,11 @@ def find_matches(db, patterns, max_matches=1, ignore_case=False, fuzzy=False): if not found: break if found and (os.path.exists(path) or TESTING): + # avoid jumping to current directory + # (call out to realpath this late to not stat all dirs) + if current_dir == decode(os.path.realpath(path)) : + continue + if path not in results: results.append(path) if len(results) >= max_matches: