diff options
author | Olle Lundberg <geek@nerd.sh> | 2014-08-15 15:53:07 +0200 |
---|---|---|
committer | Jeff Forcier <jeff@bitprophet.org> | 2014-08-25 23:32:37 -0700 |
commit | c50d023c91210eb25416bf5f3a4e05353cb16ca4 (patch) | |
tree | 59fb3f9223a8cf058f2bc123120ce0d868478518 | |
parent | 1fa69c7003bac49c22721ac694fe399f369ece8a (diff) |
Don't make unnecessary calls to LazyFqdn.__str__.
Before this patch we always tried to expand variables in the
config even if they weren't present. This meant that we made an
expensive call to LazyFqdn.__str__ the first iteration of the expand
loop, stealing precious cpu and user time.
We now check that the expansion actually exists in the config
before expanding it, this will speed up the case where %l is not
used.
This fixes #338
-rw-r--r-- | paramiko/config.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/paramiko/config.py b/paramiko/config.py index f650ee24..96ec9ef7 100644 --- a/paramiko/config.py +++ b/paramiko/config.py @@ -83,7 +83,7 @@ class SSHConfig (object): #identityfile, localforward, remoteforward keys are special cases, since they are allowed to be # specified multiple times and they should be tried in order # of specification. - + elif key in ['identityfile', 'localforward', 'remoteforward']: if key in host['config']: host['config'][key].append(value) @@ -200,10 +200,12 @@ class SSHConfig (object): for find, replace in replacements[k]: if isinstance(config[k], list): for item in range(len(config[k])): - config[k][item] = config[k][item].\ - replace(find, str(replace)) + if find in config[k][item]: + config[k][item] = config[k][item].\ + replace(find, str(replace)) else: - config[k] = config[k].replace(find, str(replace)) + if find in config[k]: + config[k] = config[k].replace(find, str(replace)) return config |