Bug 1105128 - Alias os.path functions in local scope; r=glandium

Various os.path attributes are being used in tight loops. Having local
variables prevents extra dictionary lookups.

This appears to shave 10-20ms off of the tests install manifest
processing time.

--HG--
extra : rebase_source : de941f2978cf0b1fd7c4f7401c848b61d406a2c8
extra : amend_source : e33c896856fa559197496b8227e10ab8149d146e
This commit is contained in:
Gregory Szorc 2014-11-25 18:37:11 -08:00
parent bea629df49
commit 2d7afd0fac

View File

@ -212,7 +212,12 @@ class FileCopier(FileRegistry):
result = FileCopyResult()
have_symlinks = hasattr(os, 'symlink')
destination = os.path.normpath(destination)
# Aliased to prevent attribute lookup in tight loops.
normpath = os.path.normpath
join = os.path.join
dirname = os.path.dirname
destination = normpath(destination)
# We create the destination directory specially. We can't do this as
# part of the loop doing mkdir() below because that loop munges
@ -234,9 +239,9 @@ class FileCopier(FileRegistry):
dest_files = set()
for p, f in self:
dest_files.add(os.path.normpath(os.path.join(destination, p)))
dest_files.add(normpath(join(destination, p)))
required_dirs |= set(os.path.normpath(os.path.join(destination, d))
required_dirs |= set(normpath(join(destination, d))
for d in self.required_directories())
# Ensure destination directories are in place and proper.
@ -289,7 +294,7 @@ class FileCopier(FileRegistry):
if have_symlinks:
filtered = []
for d in dirs:
full = os.path.join(root, d)
full = join(root, d)
st = os.lstat(full)
if stat.S_ISLNK(st.st_mode):
# This directory symlink is not a required
@ -308,10 +313,10 @@ class FileCopier(FileRegistry):
existing_dirs.add(root)
for d in dirs:
existing_dirs.add(os.path.join(root, d))
existing_dirs.add(join(root, d))
for f in files:
existing_files.add(os.path.join(root, f))
existing_files.add(join(root, f))
# Now we reconcile the state of the world against what we want.
@ -329,7 +334,7 @@ class FileCopier(FileRegistry):
# Install files.
for p, f in self:
destfile = os.path.join(destination, p)
destfile = join(destination, p)
if f.copy(destfile, skip_if_older):
result.updated_files.add(destfile)
else:
@ -354,7 +359,7 @@ class FileCopier(FileRegistry):
previous = ''
parents = set()
while True:
parent = os.path.dirname(parent)
parent = dirname(parent)
parents.add(parent)
if previous == parent: