[pypy-svn] r69526 - in pypy/trunk/pypy: objspace/std rpython/memory/gc rpython/memory/test

fijal at codespeak.net fijal at codespeak.net
Mon Nov 23 10:43:57 CET 2009


Author: fijal
Date: Mon Nov 23 10:43:56 2009
New Revision: 69526

Modified:
   pypy/trunk/pypy/objspace/std/stringobject.py
   pypy/trunk/pypy/objspace/std/unicodeobject.py
   pypy/trunk/pypy/rpython/memory/gc/hybrid.py
   pypy/trunk/pypy/rpython/memory/test/test_gc.py
Log:
Revert a couple of last changes, will be tried and debugged on a branch


Modified: pypy/trunk/pypy/objspace/std/stringobject.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/stringobject.py	(original)
+++ pypy/trunk/pypy/objspace/std/stringobject.py	Mon Nov 23 10:43:56 2009
@@ -351,7 +351,6 @@
 def str_join__String_ANY(space, w_self, w_list):
     list_w = space.listview(w_list)
     str_w = space.str_w
-    s = space.str_w(w_self)
     if list_w:
         self = w_self._value
         listlen = 0
@@ -368,17 +367,8 @@
                     space.wrap("sequence item %d: expected string, %s "
                                "found" % (i,
                                           space.type(w_s).getname(space, '?'))))
-            # We can do a shortcut here "if isinstance(w_s, W_StringObject)",
-            # but this should be rendered pointless by having multilist
-            # which will simply always contain strings
-            reslen += len(space.str_w(w_s))
-        reslen += len(s) * (len(list_w) - 1)
-        res = StringBuilder(reslen)
-        for i in range(len(list_w)):
-            res.append(space.str_w(list_w[i]))
-            if i != len(list_w) - 1:
-                res.append(s)
-        return space.wrap(res.build())
+            l[i] = space.str_w(w_s)
+        return space.wrap(self.join(l))
     else:
         return W_StringObject.EMPTY
 

Modified: pypy/trunk/pypy/objspace/std/unicodeobject.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/unicodeobject.py	(original)
+++ pypy/trunk/pypy/objspace/std/unicodeobject.py	Mon Nov 23 10:43:56 2009
@@ -13,7 +13,6 @@
 
 from pypy.objspace.std.formatting import mod_format
 from pypy.objspace.std.stringtype import stringstartswith, stringendswith
-from pypy.rlib.rstring import UnicodeBuilder
 
 class W_UnicodeObject(W_Object):
     from pypy.objspace.std.unicodetype import unicode_typedef as typedef
@@ -175,38 +174,29 @@
     return space.newbool(container.find(item) != -1)
 
 def unicode_join__Unicode_ANY(space, w_self, w_list):
-    l_w = space.listview(w_list)
+    l = space.listview(w_list)
     delim = w_self._value
-    if len(l_w) == 0:
+    totlen = 0
+    if len(l) == 0:
         return W_UnicodeObject.EMPTY
-    if (len(l_w) == 1 and
-        space.is_w(space.type(l_w[0]), space.w_unicode)):
-        return l_w[0]
-    lgt = 0
-    for i in range(len(l_w)):
-        w_item = l_w[i]
-        if isinstance(w_item, W_UnicodeObject):
+    if (len(l) == 1 and
+        space.is_w(space.type(l[0]), space.w_unicode)):
+        return l[0]
+    
+    values_list = [None] * len(l)
+    for i in range(len(l)):
+        item = l[i]
+        if isinstance(item, W_UnicodeObject):
             # shortcut for performane
-            lgt += len(w_item._value)
-        elif space.is_true(space.isinstance(w_item, space.w_str)):
-            lgt += len(space.str_w(w_item))
-            # some estimate, does not need to be perfect
+            item = item._value
+        elif space.is_true(space.isinstance(item, space.w_str)):
+            item = space.unicode_w(item)
         else:
             w_msg = space.mod(space.wrap('sequence item %d: expected string or Unicode'),
                               space.wrap(i))
             raise OperationError(space.w_TypeError, w_msg)
-    # now we know it's a list of unicode or string
-    lgt += len(delim) * (len(l_w) - 1)
-    builder = UnicodeBuilder(lgt)
-    for i in range(len(l_w)):
-        w_item = l_w[i]
-        if isinstance(w_item, W_UnicodeObject):
-            builder.append(w_item._value)
-        else:
-            builder.append(space.unicode_w(w_item))
-        if i != len(l_w) - 1:
-            builder.append(delim)
-    return W_UnicodeObject(builder.build())
+        values_list[i] = item
+    return W_UnicodeObject(w_self._value.join(values_list))
 
 def hash__Unicode(space, w_uni):
     s = w_uni._value

Modified: pypy/trunk/pypy/rpython/memory/gc/hybrid.py
==============================================================================
--- pypy/trunk/pypy/rpython/memory/gc/hybrid.py	(original)
+++ pypy/trunk/pypy/rpython/memory/gc/hybrid.py	Mon Nov 23 10:43:56 2009
@@ -82,7 +82,7 @@
     """
     first_unused_gcflag = _gcflag_next_bit
     prebuilt_gc_objects_are_static_roots = True
-    can_realloc = True
+    can_realloc = False
 
     # the following values override the default arguments of __init__ when
     # translating to a real backend.
@@ -240,11 +240,8 @@
             result = llop.raw_realloc_grow(llmemory.Address, source_addr,
                                            old_tot_size, tot_size)
         else:
-            if old_tot_size == tot_size:
-                result = source_addr
-            else:
-                result = llop.raw_realloc_shrink(llmemory.Address, source_addr,
-                                                 old_tot_size, tot_size)
+            result = llop.raw_realloc_shrink(llmemory.Address, source_addr,
+                                             old_tot_size, tot_size)
         if not result:
             self.gen2_resizable_objects.append(addr)
             raise MemoryError()

Modified: pypy/trunk/pypy/rpython/memory/test/test_gc.py
==============================================================================
--- pypy/trunk/pypy/rpython/memory/test/test_gc.py	(original)
+++ pypy/trunk/pypy/rpython/memory/test/test_gc.py	Mon Nov 23 10:43:56 2009
@@ -660,21 +660,6 @@
         res = self.interpret(f, [15])
         assert res == 16
 
-    def test_resizable_buffer_no_realloc(self):
-        from pypy.rpython.lltypesystem.rstr import STR
-        from pypy.rpython.annlowlevel import hlstr
-
-        def f():
-            ptr = rgc.resizable_buffer_of_shape(STR, 1)
-            ptr.chars[0] = 'a'
-            ptr = rgc.resize_buffer(ptr, 1, 2)
-            ptr.chars[1] = 'b'
-            newptr = rgc.finish_building_buffer(ptr, 2)
-            return ptr == newptr
-
-        assert self.interpret(f, []) == 1
-
-
     def test_malloc_nonmovable_fixsize(self):
         py.test.skip("Not supported")
 



More information about the Pypy-commit mailing list