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:
parent
0ec15eeb09
commit
9fc5ae1b56
1 changed files with 7 additions and 2 deletions
9
state.py
9
state.py
|
|
@ -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,7 +50,8 @@ 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('/', '^')))
|
||||||
debug2('sname: (%r) %r -> %r\n' % (os.getcwd(), t, tnew))
|
if vars.DEBUG >= 2:
|
||||||
|
debug2('sname: (%r) %r -> %r\n' % (os.getcwd(), t, tnew))
|
||||||
return v
|
return v
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue