mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-05 17:00:58 +01:00
slight efficiency improvement
This commit is contained in:
parent
90adbaf070
commit
20e698f6f1
2 changed files with 8 additions and 4 deletions
|
@ -365,12 +365,12 @@ def run_subproc(cmds, captured=True):
|
|||
suggested = {}
|
||||
path = ENV.get('PATH',[])
|
||||
for a in builtins.aliases:
|
||||
if a not in suggested and levenshtein(a, cmd) < threshold:
|
||||
if a not in suggested and levenshtein(a, cmd, threshold) < threshold:
|
||||
suggested[a] = 'Alias'
|
||||
for d in path:
|
||||
if os.path.isdir(d):
|
||||
for f in os.listdir(d):
|
||||
if f not in suggested and levenshtein(f, cmd) < threshold:
|
||||
if f not in suggested and levenshtein(f, cmd, threshold) < threshold:
|
||||
fname = os.path.join(d,f)
|
||||
suggested[f] = 'Command ({0})'.format(fname)
|
||||
suggested = OrderedDict(sorted(suggested.items(),
|
||||
|
|
|
@ -212,11 +212,15 @@ class redirect_stderr(_RedirectStream):
|
|||
_stream = "stderr"
|
||||
|
||||
|
||||
# Public Domain code, by Magnus Lie Hetland
|
||||
# Modified from Public Domain code, by Magnus Lie Hetland
|
||||
# from http://hetland.org/coding/python/levenshtein.py
|
||||
def levenshtein(a,b):
|
||||
def levenshtein(a,b,max_dist=float('inf')):
|
||||
"Calculates the Levenshtein distance between a and b."
|
||||
n, m = len(a), len(b)
|
||||
|
||||
if abs(n-m) > max_dist:
|
||||
return float('inf')
|
||||
|
||||
if n > m:
|
||||
# Make sure n <= m, to use O(min(n,m)) space
|
||||
a,b = b,a
|
||||
|
|
Loading…
Add table
Reference in a new issue