Commits

Alex Gaynor committed 3d2ff1e

Optimize match.group('name') by making it a module dict.

Comments (0)

Files changed (2)

lib-python/2.7/sre_parse.py

 
 from sre_constants import *
 
+try:
+    from __pypy__ import newdict
+except ImportError:
+    def newdict(tp):
+        return {}
+
 SPECIAL_CHARS = ".\\[{()*+?^$|"
 REPEAT_CHARS = "*+?{"
 
         self.flags = 0
         self.open = []
         self.groups = 1
-        self.groupdict = {}
+        self.groupdict = newdict("module")
     def opengroup(self, name=None):
         gid = self.groups
         self.groups = gid + 1

pypy/module/_sre/interp_sre.py

 # SRE_Pattern class
 
 class W_SRE_Pattern(Wrappable):
-    _immutable_fields_ = ["code", "flags", "num_groups"]
+    _immutable_fields_ = ["code", "flags", "num_groups", "w_indexgroup"]
 
     def cannot_copy_w(self):
         space = self.space