summaryrefslogtreecommitdiff
path: root/Lib/lib2to3/pytree.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2008-07-17 02:07:46 +0000
committerBenjamin Peterson <benjamin@python.org>2008-07-17 02:07:46 +0000
commit1ab314906396a6dfaccc5dd9c853f6ae7222ad2c (patch)
treeab7dafb77ab4a159177b3dac45050c5a96f30b21 /Lib/lib2to3/pytree.py
parenta66bb0a741060b35151673dffb0d5b87307aa7e9 (diff)
downloadcpython-git-1ab314906396a6dfaccc5dd9c853f6ae7222ad2c.tar.gz
Merged revisions 65053-65054 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3 ........ r65053 | benjamin.peterson | 2008-07-16 21:04:12 -0500 (Wed, 16 Jul 2008) | 1 line massive optimizations for 2to3 (especially fix_imports) from Nick Edds ........ r65054 | benjamin.peterson | 2008-07-16 21:05:09 -0500 (Wed, 16 Jul 2008) | 1 line normalize whitespace ........
Diffstat (limited to 'Lib/lib2to3/pytree.py')
-rw-r--r--Lib/lib2to3/pytree.py23
1 files changed, 19 insertions, 4 deletions
diff --git a/Lib/lib2to3/pytree.py b/Lib/lib2to3/pytree.py
index 18a2de34f2..cd988ac5b8 100644
--- a/Lib/lib2to3/pytree.py
+++ b/Lib/lib2to3/pytree.py
@@ -652,20 +652,35 @@ class WildcardPattern(BasePattern):
if self.name:
r[self.name] = nodes[:count]
yield count, r
+ elif self.name == "bare_name":
+ yield self._bare_name_matches(nodes)
else:
for count, r in self._recursive_matches(nodes, 0):
if self.name:
r[self.name] = nodes[:count]
yield count, r
+ def _bare_name_matches(self, nodes):
+ """Special optimized matcher for bare_name."""
+ count = 0
+ r = {}
+ done = False
+ max = len(nodes)
+ while not done and count < max:
+ done = True
+ for leaf in self.content:
+ if leaf[0].match(nodes[count], r):
+ count += 1
+ done = False
+ break
+ r[self.name] = nodes[:count]
+ return count, r
+
def _recursive_matches(self, nodes, count):
"""Helper to recursively yield the matches."""
assert self.content is not None
if count >= self.min:
- r = {}
- if self.name:
- r[self.name] = nodes[:0]
- yield 0, r
+ yield 0, {}
if count < self.max:
for alt in self.content:
for c0, r0 in generate_matches(alt, nodes):