Optimization: don't getcwd() so often.

We never chdir() except just as we exec a subprocess, so it's okay to cache
this value.  This makes strace output look cleaner, and speeds things up a
little bit when checking a large number of dependencies.

Relatedly, take a debug2() message and put it in an additional if, so that
we don't have to do so much work to calculate it when we're just going to
throw it away anyhow.
This commit is contained in:
Avery Pennarun 2010-11-24 03:45:38 -08:00
commit 9fc5ae1b56

View file

@ -27,8 +27,12 @@ def is_sane():
return not _insane return not _insane
_cwd = None
def relpath(t, base): def relpath(t, base):
t = os.path.normpath(os.path.join(os.getcwd(), t)) global _cwd
if not _cwd:
_cwd = os.getcwd()
t = os.path.normpath(os.path.join(_cwd, t))
tparts = t.split('/') tparts = t.split('/')
bparts = base.split('/') bparts = base.split('/')
for tp,bp in zip(tparts,bparts): for tp,bp in zip(tparts,bparts):
@ -46,6 +50,7 @@ def _sname(typ, t):
# FIXME: t.replace(...) is non-reversible and non-unique here! # FIXME: t.replace(...) is non-reversible and non-unique here!
tnew = relpath(t, vars.BASE) tnew = relpath(t, vars.BASE)
v = vars.BASE + ('/.redo/%s^%s' % (typ, tnew.replace('/', '^'))) v = vars.BASE + ('/.redo/%s^%s' % (typ, tnew.replace('/', '^')))
if vars.DEBUG >= 2:
debug2('sname: (%r) %r -> %r\n' % (os.getcwd(), t, tnew)) debug2('sname: (%r) %r -> %r\n' % (os.getcwd(), t, tnew))
return v return v