[pypy-svn] r48789 - in pypy/branch/ropes-unicode/pypy/objspace/std: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Mon Nov 19 15:05:45 CET 2007


Author: cfbolz
Date: Mon Nov 19 15:05:44 2007
New Revision: 48789

Modified:
   pypy/branch/ropes-unicode/pypy/objspace/std/rope.py
   pypy/branch/ropes-unicode/pypy/objspace/std/test/test_rope.py
Log:
kill some dead code and some useless XXXs


Modified: pypy/branch/ropes-unicode/pypy/objspace/std/rope.py
==============================================================================
--- pypy/branch/ropes-unicode/pypy/objspace/std/rope.py	(original)
+++ pypy/branch/ropes-unicode/pypy/objspace/std/rope.py	Mon Nov 19 15:05:44 2007
@@ -133,7 +133,6 @@
         return self.s
 
     def flatten_unicode(self):
-        # XXX not RPython yet
         return self.s.decode('latin-1')
 
     def hash_part(self):
@@ -706,40 +705,6 @@
     restart = construct_restart_positions_node(subnode)
     return _find_node(node, subnode, start, stop, restart)
 
-def _find(node, substring, start, stop, restart):
-    # XXX
-    assert node.is_bytestring()
-    len2 = len(substring)
-    i = 0
-    m = start
-    iter = SeekableItemIterator(node)
-    iter.seekforward(start)
-    c = iter.nextchar()
-    while m + i < stop:
-        if c == substring[i]:
-            i += 1
-            if i == len2:
-                return m
-            if m + i < stop:
-                c = iter.nextchar()
-        else:
-            # mismatch, go back to the last possible starting pos
-            if i==0:
-                m += 1
-                if m + i < stop:
-                    c = iter.nextchar()
-            else:
-                e = restart[i-1]
-                new_m = m + i - e
-                assert new_m <= m + i
-                seek = m + i - new_m
-                if seek:
-                    iter.seekback(m + i - new_m)
-                    c = iter.nextchar()
-                m = new_m
-                i = e
-    return -1
-
 def _find_node(node, subnode, start, stop, restart):
     len2 = subnode.length()
     m = start
@@ -777,27 +742,7 @@
                 i = e
     return -1
 
-def construct_restart_positions(s):
-    length = len(s)
-    restart = [0] * length
-    restart[0] = 0
-    i = 1
-    j = 0
-    while i < length:
-        if s[i] == s[j]:
-            j += 1
-            restart[i] = j
-            i += 1
-        elif j>0:
-            j = restart[j-1]
-        else:
-            restart[i] = 0
-            i += 1
-            j = 0
-    return restart
-
 def construct_restart_positions_node(node):
-    # really a bit overkill
     length = node.length()
     restart = [0] * length
     restart[0] = 0

Modified: pypy/branch/ropes-unicode/pypy/objspace/std/test/test_rope.py
==============================================================================
--- pypy/branch/ropes-unicode/pypy/objspace/std/test/test_rope.py	(original)
+++ pypy/branch/ropes-unicode/pypy/objspace/std/test/test_rope.py	Mon Nov 19 15:05:44 2007
@@ -423,18 +423,11 @@
     restart = construct_restart_positions_node(
         BinaryConcatNode(LiteralStringNode("aba"), LiteralStringNode("bcabab")))
     assert restart == [0, 0, 1, 2, 0, 1, 2, 3, 4]
-    restart = construct_restart_positions("ababcabab")
-    assert restart == [0, 0, 1, 2, 0, 1, 2, 3, 4]
-    restart = construct_restart_positions("ababcababb")
-    assert restart == [0, 0, 1, 2, 0, 1, 2, 3, 4, 0]
     restart = construct_restart_positions_node(
         BinaryConcatNode(LiteralStringNode("aba"), LiteralStringNode("bcababb")))
     assert restart == [0, 0, 1, 2, 0, 1, 2, 3, 4, 0]
-    restart = construct_restart_positions("ababb")
-    assert restart == [0, 0, 1, 2, 0]
     restart = construct_restart_positions_node(LiteralStringNode("ababb"))
     assert restart == [0, 0, 1, 2, 0]
-    #abababcabcabb
 
 
 def test_find():
@@ -447,6 +440,17 @@
     pos = find(node, LiteralStringNode("a"), 0, node.length())
     assert pos == 6
 
+
+def test_find_unicode():
+    node = BinaryConcatNode(LiteralUnicodeNode(u"\uaaaa\ubbbb\uaaaa"),
+                            LiteralUnicodeNode(u"\ubbbb\ucccc\uaaaa\ubbbb\uaaaa\ubbbb"))
+    pos = find(node, LiteralUnicodeNode(u"\uaaaa\ubbbb\ucccc"), 0, node.length())
+    assert pos == 2
+    node = BinaryConcatNode(LiteralUnicodeNode(u"btffp"),
+                            LiteralUnicodeNode(u"b\uaaaacbb"))
+    pos = find(node, LiteralUnicodeNode(u"\uaaaa"), 0, node.length())
+    assert pos == 6
+
 def test_fromcharlist():
     for i in range(0, 100, 10):
         chars = ["a"] * 50 + ["b"] * i



More information about the Pypy-commit mailing list