[pypy-svn] r40052 - in pypy/branch/rope-branch2/pypy/objspace/std: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Wed Mar 7 22:07:46 CET 2007


Author: cfbolz
Date: Wed Mar  7 22:07:45 2007
New Revision: 40052

Modified:
   pypy/branch/rope-branch2/pypy/objspace/std/ropeobject.py
   pypy/branch/rope-branch2/pypy/objspace/std/stringtype.py
   pypy/branch/rope-branch2/pypy/objspace/std/test/test_ropeobject.py
Log:
make ropes work with the prebuilt string options


Modified: pypy/branch/rope-branch2/pypy/objspace/std/ropeobject.py
==============================================================================
--- pypy/branch/rope-branch2/pypy/objspace/std/ropeobject.py	(original)
+++ pypy/branch/rope-branch2/pypy/objspace/std/ropeobject.py	Wed Mar  7 22:07:45 2007
@@ -8,6 +8,7 @@
 from pypy.objspace.std.noneobject import W_NoneObject
 from pypy.objspace.std.tupleobject import W_TupleObject
 from pypy.rlib.rarithmetic import ovfcheck
+from pypy.objspace.std.stringtype import wrapchar
 
 from pypy.objspace.std import rope
 
@@ -30,6 +31,10 @@
         return W_RopeObject(w_self._node)
 
 W_RopeObject.EMPTY = W_RopeObject(rope.LiteralStringNode(""))
+W_RopeObject.PREBUILT = [W_RopeObject(rope.LiteralStringNode(chr(i)))
+                             for i in range(256)]
+del i
+
 
 def rope_w(space, w_str):
     if isinstance(w_str, W_RopeObject):
@@ -48,9 +53,6 @@
 
 registerimplementation(W_RopeIterObject)
 
-def wrap_rpystr(s):
-    return W_RopeObject(rope.LiteralStringNode(s))
-
 def _is_generic(space, w_self, fun): 
     l = w_self._node.length()
     if l == 0:
@@ -319,7 +321,7 @@
         # the word is value[j+1:i+1]
         j1 = j + 1
         assert j1 >= 0
-        res_w.append(wrap_rpystr(value[j1:i+1]))
+        res_w.append(space.wrap(value[j1:i+1]))
 
         # continue to look from the character before the space before the word
         i = j - 1
@@ -342,11 +344,11 @@
         next = value.rfind(by, 0, end)
         if next < 0:
             break
-        res_w.append(wrap_rpystr(value[next+bylen: end]))
+        res_w.append(space.wrap(value[next+bylen: end]))
         end = next
         maxsplit -= 1   # NB. if it's already < 0, it stays < 0
 
-    res_w.append(wrap_rpystr(value[:end]))
+    res_w.append(space.wrap(value[:end]))
     res_w.reverse()
     return space.newlist(res_w)
 
@@ -909,7 +911,7 @@
         exc = space.call_function(space.w_IndexError,
                                   space.wrap("string index out of range"))
         raise OperationError(space.w_IndexError, exc)
-    return wrap_rpystr(node.getitem(ival))
+    return wrapchar(space, node.getitem(ival))
 
 def getitem__Rope_Slice(space, w_str, w_slice):
     node = w_str._node
@@ -1097,7 +1099,7 @@
         raise OperationError(space.w_StopIteration, space.w_None) 
     try:
         char = w_ropeiter.char_iter.next()
-        w_item = wrap_rpystr(char)
+        w_item = space.wrap(char)
     except StopIteration:
         w_ropeiter.node = None
         w_ropeiter.char_iter = None

Modified: pypy/branch/rope-branch2/pypy/objspace/std/stringtype.py
==============================================================================
--- pypy/branch/rope-branch2/pypy/objspace/std/stringtype.py	(original)
+++ pypy/branch/rope-branch2/pypy/objspace/std/stringtype.py	Wed Mar  7 22:07:45 2007
@@ -5,11 +5,14 @@
 
 def wrapstr(space, s):
     from pypy.objspace.std.stringobject import W_StringObject
+    from pypy.objspace.std.ropeobject import rope, W_RopeObject
     if space.config.objspace.std.sharesmallstr:
         if space.config.objspace.std.withprebuiltchar:
             # share characters and empty string
             if len(s) <= 1:
                 if len(s) == 0:
+                    if space.config.objspace.std.withrope:
+                        return W_RopeObject.EMPTY
                     return W_StringObject.EMPTY
                 else:
                     s = s[0]     # annotator hint: a single char
@@ -17,17 +20,23 @@
         else:
             # only share the empty string
             if len(s) == 0:
+                if space.config.objspace.std.withrope:
+                    return W_RopeObject.EMPTY
                 return W_StringObject.EMPTY
     if space.config.objspace.std.withrope:
-        from pypy.objspace.std.ropeobject import rope, W_RopeObject
         return W_RopeObject(rope.LiteralStringNode(s))
     return W_StringObject(s)
 
 def wrapchar(space, c):
     from pypy.objspace.std.stringobject import W_StringObject
+    from pypy.objspace.std.ropeobject import rope, W_RopeObject
     if space.config.objspace.std.withprebuiltchar:
+        if space.config.objspace.std.withrope:
+            return W_RopeObject.PREBUILT[ord(c)]
         return W_StringObject.PREBUILT[ord(c)]
     else:
+        if space.config.objspace.std.withrope:
+            return W_RopeObject(rope.LiteralStringNode(c))
         return W_StringObject(c)
 
 def sliced(space, s, start, stop):

Modified: pypy/branch/rope-branch2/pypy/objspace/std/test/test_ropeobject.py
==============================================================================
--- pypy/branch/rope-branch2/pypy/objspace/std/test/test_ropeobject.py	(original)
+++ pypy/branch/rope-branch2/pypy/objspace/std/test/test_ropeobject.py	Wed Mar  7 22:07:45 2007
@@ -72,3 +72,33 @@
 
     def setup_class(cls):
         cls.space = gettestobjspace(**{"objspace.std.withrope": True})
+
+class AppTestPrebuilt(test_stringobject.AppTestStringObject):
+    def setup_class(cls):
+        cls.space = gettestobjspace(**{"objspace.std.withrope": True,
+                                       "objspace.std.withprebuiltchar": True})
+
+    def test_hash(self):
+        # does not make sense, since our hash is different than CPython's
+        pass
+ 
+
+class AppTestShare(test_stringobject.AppTestStringObject):
+    def setup_class(cls):
+        cls.space = gettestobjspace(**{"objspace.std.withrope": True,
+                                       "objspace.std.sharesmallstr": True})
+
+    def test_hash(self):
+        # does not make sense, since our hash is different than CPython's
+        pass
+ 
+class AppTestPrebuiltShare(test_stringobject.AppTestStringObject):
+    def setup_class(cls):
+        cls.space = gettestobjspace(**{"objspace.std.withrope": True,
+                                       "objspace.std.withprebuiltchar": True,
+                                       "objspace.std.sharesmallstr": True})
+
+    def test_hash(self):
+        # does not make sense, since our hash is different than CPython's
+        pass
+ 



More information about the Pypy-commit mailing list