diff options
author | Zac Medico <zmedico@gentoo.org> | 2008-04-14 21:56:16 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2008-04-14 21:56:16 +0000 |
commit | 503e475d456bec71472fcfc42fc82541f8b4feec (patch) | |
tree | ed9c15db720a9df9c672552f05a4f55fdc19e021 /pym/portage.py | |
parent | 29418012a5af7d651a287c9df75565499b07a076 (diff) | |
download | portage-503e475d456bec71472fcfc42fc82541f8b4feec.tar.gz portage-503e475d456bec71472fcfc42fc82541f8b4feec.tar.bz2 portage-503e475d456bec71472fcfc42fc82541f8b4feec.zip |
In config.setcpv() and regenerate(), replace str.startswith() calls with
slice comparison. It's not pretty but performance is critical in this section
of code and there is a measurable performance difference. (trunk r9896)
svn path=/main/branches/2.1.2/; revision=9897
Diffstat (limited to 'pym/portage.py')
-rw-r--r-- | pym/portage.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/pym/portage.py b/pym/portage.py index 482ab8ff2..063acc5f7 100644 --- a/pym/portage.py +++ b/pym/portage.py @@ -2091,13 +2091,14 @@ class config: self.usemask.discard("test") # Use the calculated USE flags to regenerate the USE_EXPAND flags so - # that they are consistent. + # that they are consistent. For optimal performance, use slice + # comparison instead of startswith(). use_expand = self.get("USE_EXPAND", "").split() for var in use_expand: prefix = var.lower() + "_" prefix_len = len(prefix) expand_flags = set([ x[prefix_len:] for x in use \ - if x.startswith(prefix) ]) + if x[:prefix_len] == prefix ]) var_split = self.get(var, "").split() # Preserve the order of var_split because it can matter for things # like LINGUAS. @@ -2108,13 +2109,13 @@ class config: var_split = [ x for x in var_split if x != "*" ] has_iuse = set() for x in iuse_implicit: - if x.startswith(prefix): + if x[:prefix_len] == prefix: has_iuse.add(x[prefix_len:]) if has_wildcard: # * means to enable everything in IUSE that's not masked if has_iuse: for x in iuse_implicit: - if x.startswith(prefix) and x not in self.usemask: + if x[:prefix_len] == prefix and x not in self.usemask: suffix = x[prefix_len:] var_split.append(suffix) use.add(x) @@ -2450,6 +2451,8 @@ class config: self.uvlist.append(self.configdict[x]) self.uvlist.reverse() + # For optimal performance, use slice + # comparison instead of startswith(). myflags = set() for curdb in self.uvlist: cur_use_expand = [x for x in use_expand if x in curdb] @@ -2479,8 +2482,9 @@ class config: is_not_incremental = var not in myincrementals if is_not_incremental: prefix = var_lower + "_" + prefix_len = len(prefix) for x in list(myflags): - if x.startswith(prefix): + if x[:prefix_len] == prefix: myflags.remove(x) for x in curdb[var].split(): if x[0] == "+": |