summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2010-07-25 12:11:19 -0700
committerZac Medico <zmedico@gentoo.org>2010-07-25 12:11:19 -0700
commit636951ccdc6eeddf7776ef2ebcffbeb212fc9b46 (patch)
tree738f118f289bec6f75dce0470ab07d0fff34c668
parent9caa9b5a7a84c7288f9cda98a4ecf85d10aa30c1 (diff)
downloadportage-636951ccdc6eeddf7776ef2ebcffbeb212fc9b46.tar.gz
portage-636951ccdc6eeddf7776ef2ebcffbeb212fc9b46.tar.bz2
portage-636951ccdc6eeddf7776ef2ebcffbeb212fc9b46.zip
Make extended_cp_match() cache regular expressions for re-use.
-rw-r--r--pym/portage/dep/__init__.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/pym/portage/dep/__init__.py b/pym/portage/dep/__init__.py
index 80e2b4c78..9720a510e 100644
--- a/pym/portage/dep/__init__.py
+++ b/pym/portage/dep/__init__.py
@@ -754,14 +754,20 @@ class Atom(_atom_base):
memo[id(self)] = self
return self
+_extended_cp_re_cache = {}
+
def extended_cp_match(extended_cp, other_cp):
"""
Checks if an extended syntax cp matches a non extended cp
"""
# Escape special '+' and '.' characters which are allowed in atoms,
# and convert '*' to regex equivalent.
- extended_cp_re = re.compile("^" + extended_cp.replace("+", r"\+").replace(
- ".", r"\.").replace('*', '[^/]*') + "$")
+ global _extended_cp_re_cache
+ extended_cp_re = _extended_cp_re_cache.get(extended_cp)
+ if extended_cp_re is None:
+ extended_cp_re = re.compile("^" + extended_cp.replace(
+ "+", r"\+").replace(".", r"\.").replace('*', '[^/]*') + "$")
+ _extended_cp_re_cache[extended_cp] = extended_cp_re
return extended_cp_re.match(other_cp) is not None
class ExtendedAtomDict(object):