Commits

Maciej Fijalkowski committed f930209

What the hell, implement this optimization

Comments (0)

Files changed (2)

pypy/objspace/std/stringobject.py

             maxsplit -= 1   # NB. if it's already < 0, it stays < 0
 
         # the word is value[i:j]
-        res_w.append(sliced(space, value, i, j))
+        res_w.append(sliced(space, value, i, j, w_self))
 
         # continue to look from the character following the space after the word
         i = j + 1
         next = value.find(by, start)
         if next < 0:
             break
-        res_w.append(sliced(space, value, start, next))
+        res_w.append(sliced(space, value, start, next, w_self))
         start = next + bylen
         maxsplit -= 1   # NB. if it's already < 0, it stays < 0
     
-    res_w.append(sliced(space, value, start, len(value)))
+    res_w.append(sliced(space, value, start, len(value), w_self))
     return space.newlist(res_w)
 
 def str_rsplit__String_None_ANY(space, w_self, w_none, w_maxsplit=-1):
         # the word is value[j+1:i+1]
         j1 = j + 1
         assert j1 >= 0
-        res_w.append(sliced(space, value, j1, i+1))
+        res_w.append(sliced(space, value, j1, i+1, w_self))
 
         # continue to look from the character before the space before the word
         i = j - 1
         next = value.rfind(by, 0, end)
         if next < 0:
             break
-        res_w.append(sliced(space, value, next+bylen, end))
+        res_w.append(sliced(space, value, next+bylen, end, w_self))
         end = next
         maxsplit -= 1   # NB. if it's already < 0, it stays < 0
 
-    res_w.append(sliced(space, value, 0, end))
+    res_w.append(sliced(space, value, 0, end, w_self))
     res_w.reverse()
     return space.newlist(res_w)
 
     if pos == -1:
         return space.newtuple([w_self, space.wrap(''), space.wrap('')])
     else:
-        return space.newtuple([sliced(space, self, 0, pos),
+        return space.newtuple([sliced(space, self, 0, pos, w_self),
                                w_sub,
-                               sliced(space, self, pos+len(sub), len(self))])
+                               sliced(space, self, pos+len(sub), len(self),
+                                      w_self)])
 
 def str_rpartition__String_String(space, w_self, w_sub):
     self = w_self._value
     if pos == -1:
         return space.newtuple([space.wrap(''), space.wrap(''), w_self])
     else:
-        return space.newtuple([sliced(space, self, 0, pos),
+        return space.newtuple([sliced(space, self, 0, pos, w_self),
                                w_sub,
-                               sliced(space, self, pos+len(sub), len(self))])
+                               sliced(space, self, pos+len(sub), len(self), w_self)])
 
 
 def str_index__String_String_ANY_ANY(space, w_self, w_sub, w_start, w_end):
            rpos -= 1
        
     assert rpos >= lpos    # annotator hint, don't remove
-    return sliced(space, u_self, lpos, rpos)
+    return sliced(space, u_self, lpos, rpos, w_self)
 
 def _strip_none(space, w_self, left, right):
     "internal function called by str_xstrip methods"
            rpos -= 1
        
     assert rpos >= lpos    # annotator hint, don't remove
-    return sliced(space, u_self, lpos, rpos)
+    return sliced(space, u_self, lpos, rpos, w_self)
 
 def str_strip__String_String(space, w_self, w_chars):
     return _strip(space, w_self, w_chars, left=1, right=1)
             i += 1
         if u_keepends:
             eol = i
-        strs_w.append(sliced(space, data, j, eol))
+        strs_w.append(sliced(space, data, j, eol, w_self))
         j = i
 
     if j < selflen:
-        strs_w.append(sliced(space, data, j, len(data)))
+        strs_w.append(sliced(space, data, j, len(data), w_self))
 
     return space.newlist(strs_w)
 
         return W_StringObject.EMPTY
     elif step == 1:
         assert start >= 0 and stop >= 0
-        return sliced(space, s, start, stop)
+        return sliced(space, s, start, stop, w_str)
     else:
         str = "".join([s[start + i*step] for i in range(sl)])
     return wrapstr(space, str)
     if start == stop:
         return W_StringObject.EMPTY
     else:
-        return sliced(space, s, start, stop)
+        return sliced(space, s, start, stop, w_str)
 
 def mul_string_times(space, w_str, w_times):
     try:

pypy/objspace/std/stringtype.py

             return W_RopeObject(rope.LiteralStringNode(c))
         return W_StringObject(c)
 
-def sliced(space, s, start, stop):
+def sliced(space, s, start, stop, orig_obj):
     assert start >= 0
     assert stop >= 0 
     assert not space.config.objspace.std.withrope
+    if start == 0 and stop == len(s) and space.is_w(space.type(orig_obj), space.w_str):
+        return orig_obj
     if space.config.objspace.std.withstrslice:
         from pypy.objspace.std.strsliceobject import W_StringSliceObject
         # XXX heuristic, should be improved!
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.