[pypy-svn] r49306 - in pypy/dist/pypy/rlib: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Mon Dec 3 00:18:44 CET 2007
Author: cfbolz
Date: Mon Dec 3 00:18:42 2007
New Revision: 49306
Modified:
pypy/dist/pypy/rlib/rope.py
pypy/dist/pypy/rlib/test/test_rope.py
Log:
an off-by-one error. also optimize the FindIterator for the case where the
pattern is longer than the bit of the text string where I am searching in.
Modified: pypy/dist/pypy/rlib/rope.py
==============================================================================
--- pypy/dist/pypy/rlib/rope.py (original)
+++ pypy/dist/pypy/rlib/rope.py Mon Dec 3 00:18:42 2007
@@ -698,7 +698,7 @@
if (stop - start) < 0:
return -1
return start
- if len2 >= stop - start:
+ if len2 > stop - start:
return -1
restart = construct_restart_positions_node(subnode)
return _find_node(node, subnode, start, stop, restart)
@@ -1079,16 +1079,20 @@
len1 = self.length = node.length()
len2 = sub.length()
self.search_length = len2
+ self.start = start
+ if stop == -1 or stop > len1:
+ stop = len1
+ self.stop = stop
if len2 == 0:
self.restart_positions = None
elif len2 == 1:
self.restart_positions = None
+ elif len2 > stop - start:
+ self.restart_positions = None
+ # ensure that a StopIteration is immediately raised
+ self.stop = self.start
else:
self.restart_positions = construct_restart_positions_node(sub)
- self.start = start
- if stop == -1 or stop > len1:
- stop = len1
- self.stop = stop
def next(self):
if self.search_length == 0:
Modified: pypy/dist/pypy/rlib/test/test_rope.py
==============================================================================
--- pypy/dist/pypy/rlib/test/test_rope.py (original)
+++ pypy/dist/pypy/rlib/test/test_rope.py Mon Dec 3 00:18:42 2007
@@ -439,6 +439,8 @@
assert pos == 6
pos = find(node, LiteralStringNode("aaa"), 0, 2)
assert pos == -1
+ pos = find(node, LiteralStringNode("btf"), 0, 3)
+ assert pos == 0
def test_find_unicode():
More information about the pypy-svn
mailing list