summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2008-04-14 21:13:20 +0000
committerZac Medico <zmedico@gentoo.org>2008-04-14 21:13:20 +0000
commit6507674957bd65faff14a25bcfcd117f9a9f4501 (patch)
tree448efb3746ea0659b38510822bbc8d724ee474f9
parent1a08212fbc0ce06f96cbc3bca839bcda9dba546a (diff)
downloadportage-6507674957bd65faff14a25bcfcd117f9a9f4501.tar.gz
portage-6507674957bd65faff14a25bcfcd117f9a9f4501.tar.bz2
portage-6507674957bd65faff14a25bcfcd117f9a9f4501.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. svn path=/main/trunk/; revision=9896
-rw-r--r--pym/portage/__init__.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py
index 5c712a472..a20e40ecb 100644
--- a/pym/portage/__init__.py
+++ b/pym/portage/__init__.py
@@ -2030,13 +2030,14 @@ class config(object):
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.
@@ -2047,13 +2048,13 @@ class config(object):
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)
@@ -2447,6 +2448,8 @@ class config(object):
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]
@@ -2476,8 +2479,9 @@ class config(object):
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] == "+":