Commits

Alex Gaynor committed 58ea044

removed unused strjoin objects

Comments (0)

Files changed (8)

pypy/config/pypyoption.py

                    requires=[("objspace.std.withsmallint", False)]),
                              #  ^^^ because of missing delegate_xx2yy
 
-        BoolOption("withstrslice", "use strings optimized for slicing",
-                   default=False),
-
         BoolOption("withstrbuf", "use strings optimized for addition (ver 2)",
                    default=False),
 
         config.objspace.std.suggest(withrangelist=True)
         config.objspace.std.suggest(withprebuiltchar=True)
         config.objspace.std.suggest(withmapdict=True)
-        config.objspace.std.suggest(withstrslice=True)
         if not IS_64_BITS:
             config.objspace.std.suggest(withsmalllong=True)
 

pypy/doc/config/objspace.std.withstrslice.txt

-Enable "string slice" objects.
-
-See the page about `Standard Interpreter Optimizations`_ for more details.
-
-.. _`Standard Interpreter Optimizations`: ../interpreter-optimizations.html#string-slice-objects
-
-

pypy/doc/interpreter-optimizations.rst

 Object Optimizations
 ====================
 
-String Optimizations
---------------------
-
-String-Slice Objects
-++++++++++++++++++++
-
-String-slice objects are another implementation of the Python ``str`` type.
-They represent the lazy slicing of a string without actually performing the
-slicing (which would involve copying). This is only done for slices of step
-one. When the actual value of the string slice object is needed, the slicing
-is done (although a lot of string methods don't make this necessary). This
-makes string slicing a very efficient operation. It also saves memory in some
-cases but can also lead to memory leaks, since the string slice retains a
-reference to the original string (to make this a bit less likely, we don't
-use lazy slicing when the slice would be much shorter than the original
-string.  There is also a minimum number of characters below which being lazy
-is not saving any time over making the copy).
-
-You can enable this feature with the :config:`objspace.std.withstrslice` option.
-
 Integer Optimizations
 ---------------------
 

pypy/doc/objspace.rst

 instances.  It is possible to provide *several* implementations of the
 instances of the same Python type, by writing several ``W_XxxObject``
 classes.  Every place that instantiates a new object of that Python type
-can decide which ``W_XxxObject`` class to instantiate.  For example, the
-regular string implementation is ``W_StringObject``, but we also have a
-``W_StringSliceObject`` class whose instances contain a string, a start
-index, and a stop index; it is used as the result of a string slicing
-operation to avoid the copy of all the characters in the slice into a
-new buffer.
+can decide which ``W_XxxObject`` class to instantiate.
 
 From the user's point of view, the multiple internal ``W_XxxObject``
 classes are not visible: they are still all instances of exactly the
   done with a slice object, and performs tuple slicing instead.
 
 * ``getitem__String_Slice``: called when the first argument is a
-  W_StringObject and the second argument is a slice object.  When the
-  special string slices optimization is enabled, this returns an
-  instance of W_StringSliceObject.
-
-* ``getitem__StringSlice_ANY``: called when the first argument is a
-  W_StringSliceObject.  This implementation adds the provided index to
-  the original start of the slice stored in the W_StringSliceObject
-  instance.  This allows constructs like ``a = s[10:100]; print a[5]``
-  to return the 15th character of ``s`` without having to perform any
-  buffer copying.
+  W_StringObject and the second argument is a slice object.
 
 Note how the multimethod dispatch logic helps writing new object
 implementations without having to insert hooks into existing code.  Note

pypy/objspace/std/model.py

     "withsmalltuple" : ["smalltupleobject.W_SmallTupleObject"],
     "withsmallint"   : ["smallintobject.W_SmallIntObject"],
     "withsmalllong"  : ["smalllongobject.W_SmallLongObject"],
-    "withstrslice"   : ["strsliceobject.W_StringSliceObject"],
     "withstrbuf"     : ["strbufobject.W_StringBufferObject"],
     "withtproxy" : ["proxyobject.W_TransparentList",
                     "proxyobject.W_TransparentDict"],
         self.typeorder[stringobject.W_StringObject] += [
             (unicodeobject.W_UnicodeObject, unicodeobject.delegate_String2Unicode),
             ]
-        if config.objspace.std.withstrslice:
-            from pypy.objspace.std import strsliceobject
-            self.typeorder[strsliceobject.W_StringSliceObject] += [
-                (stringobject.W_StringObject,
-                                       strsliceobject.delegate_slice2str),
-                (unicodeobject.W_UnicodeObject,
-                                       strsliceobject.delegate_slice2unicode),
-                ]
         if config.objspace.std.withstrbuf:
             from pypy.objspace.std import strbufobject
             self.typeorder[strbufobject.W_StringBufferObject] += [

pypy/objspace/std/stringtype.py

     assert stop >= 0
     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!
-        if (stop - start) > len(s) * 0.20 + 40:
-            return W_StringSliceObject(s, start, stop)
     return wrapstr(space, s[start:stop])
 
 def joined2(space, str1, str2):

pypy/objspace/std/strsliceobject.py

-from pypy.interpreter.error import OperationError
-from pypy.objspace.std.model import registerimplementation, W_Object
-from pypy.objspace.std.register_all import register_all
-from pypy.objspace.std.stringobject import W_AbstractStringObject
-from pypy.objspace.std.stringobject import W_StringObject
-from pypy.objspace.std.unicodeobject import delegate_String2Unicode
-from pypy.objspace.std.sliceobject import W_SliceObject, normalize_simple_slice
-from pypy.objspace.std.tupleobject import W_TupleObject
-from pypy.objspace.std import slicetype
-from pypy.objspace.std.inttype import wrapint
-
-from pypy.objspace.std.stringtype import wrapstr, wrapchar, sliced, \
-     stringendswith, stringstartswith
-
-
-class W_StringSliceObject(W_AbstractStringObject):
-    from pypy.objspace.std.stringtype import str_typedef as typedef
-
-    def __init__(w_self, str, start, stop):
-        assert start >= 0
-        assert stop >= 0 
-        w_self.str = str
-        w_self.start = start
-        w_self.stop = stop
-
-    def force(w_self):
-        if w_self.start == 0 and w_self.stop == len(w_self.str):
-            return w_self.str
-        str = w_self.str[w_self.start:w_self.stop]
-        w_self.str = str
-        w_self.start = 0
-        w_self.stop = len(str)
-        return str
-
-    def str_w(w_self, space):
-        return w_self.force()
-
-    def __repr__(w_self):
-        """ representation for debugging purposes """
-        return "%s(%r[%d:%d])" % (w_self.__class__.__name__,
-                                  w_self.str, w_self.start, w_self.stop)
-
-
-registerimplementation(W_StringSliceObject)
-
-
-def delegate_slice2str(space, w_strslice):
-    return wrapstr(space, w_strslice.force())
-
-def delegate_slice2unicode(space, w_strslice):
-    w_str = wrapstr(space, w_strslice.force())
-    return delegate_String2Unicode(space, w_str)
-
-# ____________________________________________________________
-
-def contains__StringSlice_String(space, w_self, w_sub):
-    sub = w_sub._value
-    return space.newbool(w_self.str.find(sub, w_self.start, w_self.stop) >= 0)
-
-
-def _convert_idx_params(space, w_self, w_sub, w_start, w_end):
-    length = w_self.stop - w_self.start
-    sub = w_sub._value
-    start, end = slicetype.unwrap_start_stop(
-            space, length, w_start, w_end, True)
-
-    assert start >= 0
-    assert end >= 0
-
-    return (w_self.str, sub, w_self.start + start, w_self.start + end)
-
-
-def str_find__StringSlice_String_ANY_ANY(space, w_self, w_sub, w_start, w_end):
-    (self, sub, start, end) = _convert_idx_params(space, w_self, w_sub, w_start, w_end)
-    res = self.find(sub, start, end)
-    if res >= 0:
-        return space.wrap(res - w_self.start)
-    else:
-        return space.wrap(res)
-
-def str_partition__StringSlice_String(space, w_self, w_sub):
-    self = w_self.str
-    sub = w_sub._value
-    if not sub:
-        raise OperationError(space.w_ValueError,
-                             space.wrap("empty separator"))
-    pos = self.find(sub, w_self.start, w_self.stop)
-    if pos == -1:
-        return space.newtuple([w_self, space.wrap(''), space.wrap('')])
-    else:
-        return space.newtuple([sliced(space, self, w_self.start, pos, w_self),
-                               w_sub,
-                               sliced(space, self, pos+len(sub), w_self.stop,
-                                      w_self)])
-
-def str_rpartition__StringSlice_String(space, w_self, w_sub):
-    self = w_self.str
-    sub = w_sub._value
-    if not sub:
-        raise OperationError(space.w_ValueError,
-                             space.wrap("empty separator"))
-    pos = self.rfind(sub, w_self.start, w_self.stop)
-    if pos == -1:
-        return space.newtuple([space.wrap(''), space.wrap(''), w_self])
-    else:
-        return space.newtuple([sliced(space, self, w_self.start, pos, w_self),
-                               w_sub,
-                               sliced(space, self, pos+len(sub), w_self.stop,
-                                      w_self)])
-
-
-def str_count__StringSlice_String_ANY_ANY(space, w_self, w_arg, w_start, w_end): 
-    (s, arg, start, end) =  _convert_idx_params(
-            space, w_self, w_arg, w_start, w_end)
-    return wrapint(space, s.count(arg, start, end))
-
-def str_rfind__StringSlice_String_ANY_ANY(space, w_self, w_sub, w_start, w_end):
-    (self, sub, start, end) =  _convert_idx_params(space, w_self, w_sub, w_start, w_end)
-    res = self.rfind(sub, start, end)
-    if res >= 0:
-        return space.wrap(res - w_self.start)
-    else:
-        return space.wrap(res)
-
-def str_index__StringSlice_String_ANY_ANY(space, w_self, w_sub, w_start, w_end):
-    (self, sub, start, end) =  _convert_idx_params(space, w_self, w_sub, w_start, w_end)
-    res = self.find(sub, start, end)
-    if res < 0:
-        raise OperationError(space.w_ValueError,
-                             space.wrap("substring not found in string.index"))
-
-    return space.wrap(res - w_self.start)
-
-
-def str_rindex__StringSlice_String_ANY_ANY(space, w_self, w_sub, w_start, w_end):
-    (self, sub, start, end) =  _convert_idx_params(space, w_self, w_sub, w_start, w_end)
-    res = self.rfind(sub, start, end)
-    if res < 0:
-        raise OperationError(space.w_ValueError,
-                             space.wrap("substring not found in string.rindex"))
-
-    return space.wrap(res - w_self.start)
-
-def str_endswith__StringSlice_String_ANY_ANY(space, w_self, w_suffix, w_start, w_end):
-    (u_self, suffix, start, end) = _convert_idx_params(space, w_self,
-                                                       w_suffix, w_start, w_end)
-    return space.newbool(stringendswith(u_self, suffix, start, end))
-
-def str_endswith__StringSlice_Tuple_ANY_ANY(space, w_self, w_suffixes, w_start, w_end):
-    (u_self, _, start, end) = _convert_idx_params(space, w_self,
-                                                  space.wrap(''), w_start, w_end)
-    for w_suffix in space.fixedview(w_suffixes):
-        suffix = space.str_w(w_suffix) 
-        if stringendswith(u_self, suffix, start, end):
-            return space.w_True
-    return space.w_False
-
-def str_startswith__StringSlice_String_ANY_ANY(space, w_self, w_prefix, w_start, w_end):
-    (u_self, prefix, start, end) = _convert_idx_params(space, w_self,
-                                                       w_prefix, w_start, w_end)
-    return space.newbool(stringstartswith(u_self, prefix, start, end))
-
-def str_startswith__StringSlice_Tuple_ANY_ANY(space, w_self, w_prefixes, w_start, w_end):
-    (u_self, _, start, end) = _convert_idx_params(space, w_self, space.wrap(''),
-                                                  w_start, w_end)
-    for w_prefix in space.fixedview(w_prefixes):
-        prefix = space.str_w(w_prefix)
-        if stringstartswith(u_self, prefix, start, end):
-            return space.w_True
-    return space.w_False
-
-def getitem__StringSlice_ANY(space, w_str, w_index):
-    ival = space.getindex_w(w_index, space.w_IndexError, "string index")
-    slen = w_str.stop - w_str.start
-    if ival < 0:
-        ival += slen
-    if ival < 0 or ival >= slen:
-        exc = space.call_function(space.w_IndexError,
-                                  space.wrap("string index out of range"))
-        raise OperationError(space.w_IndexError, exc)
-    return wrapchar(space, w_str.str[w_str.start + ival])
-
-def getitem__StringSlice_Slice(space, w_str, w_slice):
-    w = space.wrap
-    length = w_str.stop - w_str.start
-    start, stop, step, sl = w_slice.indices4(space, length)
-    if sl == 0:
-        return W_StringObject.EMPTY
-    else:
-        s = w_str.str
-        start = w_str.start + start
-        if step == 1:
-            stop = w_str.start + stop
-            assert start >= 0 and stop >= 0
-            return W_StringSliceObject(s, start, stop)
-        else:
-            str = "".join([s[start + i*step] for i in range(sl)])
-    return wrapstr(space, str)
-
-def getslice__StringSlice_ANY_ANY(space, w_str, w_start, w_stop):
-    length = w_str.stop - w_str.start
-    start, stop = normalize_simple_slice(space, length, w_start, w_stop)
-    sl = stop - start
-    if sl == 0:
-        return W_StringObject.EMPTY
-    else:
-        s = w_str.str
-        start = w_str.start + start
-        stop = w_str.start + stop
-        return W_StringSliceObject(s, start, stop)
-
-def len__StringSlice(space, w_str):
-    return space.wrap(w_str.stop - w_str.start)
-
-
-def str__StringSlice(space, w_str):
-    if type(w_str) is W_StringSliceObject:
-        return w_str
-    return W_StringSliceObject(w_str.str, w_str.start, w_str.stop)
-
-
-from pypy.objspace.std import stringtype
-register_all(vars(), stringtype)

pypy/objspace/std/test/test_strsliceobject.py

-import py
-
-from pypy.objspace.std.test import test_stringobject
-from pypy.interpreter import gateway
-from pypy.objspace.std.strsliceobject import W_StringSliceObject
-
-class AppTestStringObject(test_stringobject.AppTestStringObject):
-    spaceconfig = {"objspace.std.withstrslice": True}
-
-    def setup_class(cls):
-        def not_forced(space, w_s):
-            return space.wrap(isinstance(w_s, W_StringSliceObject) and
-                              (w_s.start != 0 or w_s.stop != len(w_s.str)))
-        cls.w_not_forced = cls.space.wrap(gateway.interp2app(not_forced))
-
-    def test_basic(self):
-        import __pypy__
-        def slice(s): return (s*3)[len(s):-len(s)]
-        s = slice('0123456789' * 20)
-        assert len(s) == 200
-        assert self.not_forced(s)
-        assert s[5] == '5'
-        assert s[-2] == '8'
-        assert s[3:7] == '3456'
-        assert 'W_StringSliceObject' in __pypy__.internal_repr(s)
-        # when the slice is too short, don't use the slice string object
-        assert 'W_StringObject' in __pypy__.internal_repr("abcdefgh"[3:7])
-        s2 = s.upper()
-        assert not self.not_forced(s)
-
-    def test_find(self):
-        import __pypy__
-        def slice(s): return (s*3)[len(s):-len(s)]
-        s = slice('abcdefghiabc' + "X" * 100)
-        assert 'W_StringSliceObject' in __pypy__.internal_repr(s)
-        assert slice('abcdefghiabc' + 'X' * 100) == 'abcdefghiabc' + 'X' * 100
-        res = s.find('abc')
-        assert res == 0
-        assert s.find('abc', 1) == 9
-        assert s.find('def', 4) == -1
-
-    def test_index(self):
-        import __pypy__, sys
-        m = sys.maxint
-        def slice(s): return (s*3)[len(s):-len(s)]
-        s = slice('abcdefghiabc' * 20)
-        assert 'W_StringSliceObject' in __pypy__.internal_repr(s)
-        assert s.index('') == 0
-        assert s.index('def') == 3
-        assert s.index('abc') == 0
-        assert s.index('abc', 1) == 9
-        assert s.index('def', -4*m, 4*m) == 3
-        raises(ValueError, s.index, 'hib')
-        raises(ValueError, slice('abcdefghiab' + "X" * 100).index, 'abc', 1)
-        raises(ValueError, slice('abcdefghi'  + "X" * 20).index, 'ghi', 8)
-        raises(ValueError, slice('abcdefghi' + "X" * 20).index, 'ghi', -1)
-        raises(TypeError, slice('abcdefghijklmn' * 20).index, 'abc', 0, 0.0)
-        raises(TypeError, slice('abcdefghijklmn' * 20).index, 'abc', -10.0, 30)
-
-    def test_rfind(self):
-        import __pypy__
-        def slice(s): return (s*3)[len(s):-len(s)]
-        s = slice('abcdefghiabc' + "X" * 100)
-        assert 'W_StringSliceObject' in __pypy__.internal_repr(s)
-        assert s.rfind('abc') == 9
-        assert s.rfind('') == 112
-        assert s.rfind('abcd') == 0
-        assert s.rfind('abcz') == -1
-
-    def test_rindex(self):
-        import __pypy__
-        from sys import maxint
-        def slice(s): return (s*3)[len(s):-len(s)]
-        s = slice("X" * 100 + 'abcdefghiabc')
-        assert 'W_StringSliceObject' in __pypy__.internal_repr(s)
-        assert s.rindex('') == 112
-        assert s.rindex('def') == 103
-        assert s.rindex('abc') == 109
-        assert s.rindex('abc', 0, -1) == 100
-        assert s.rindex('abc', -4*maxint, 4*maxint) == 109
-        raises(ValueError, slice('abcdefghiabc' * 20).rindex, 'hib')
-        raises(ValueError, slice('defghiabc' + "X" * 100).rindex, 'def', 1)
-        raises(ValueError, slice('defghiabc' + "X" * 100).rindex, 'abc', 0, -101)
-        raises(ValueError, slice('abcdefghi' + "X" * 100).rindex, 'ghi', 0, 8)
-        raises(ValueError, slice('abcdefghi' + "X" * 100).rindex, 'ghi', 0, -101)
-        raises(TypeError, slice('abcdefghijklmn' + "X" * 100).rindex,
-               'abc', 0, 0.0)
-        raises(TypeError, slice('abcdefghijklmn' + "X" * 100).rindex,
-               'abc', -10.0, 30)
-
-    def test_contains(self):
-        import __pypy__
-        def slice(s): return (s*3)[len(s):-len(s)]
-        s = slice("abc" + "X" * 100)
-        assert 'W_StringSliceObject' in __pypy__.internal_repr(s)
-        assert '' in s
-        assert 'a' in s
-        assert 'ab' in s
-        assert not 'd' in s
-        raises(TypeError, slice('a' * 100).__contains__, 1)
-        
-    def test_hash(self):
-        import __pypy__
-        # check that we have the same hash as CPython for at least 31 bits
-        # (but don't go checking CPython's special case -1)
-        # disabled: assert hash('') == 0 --- different special case
-        def slice(s): return (s*3)[len(s):-len(s)]
-        s = slice('a' * 101)
-        assert 'W_StringSliceObject' in __pypy__.internal_repr(s)
-        assert hash(s) & 0x7fffffff == 0x7e0bce58
-
-    def test_strip_produces_strslices(self):
-        import __pypy__
-        s = ("abc" + "X" * 100 + "," + "Y" * 100 + "abc").strip("abc")
-        assert "W_StringSliceObject" in __pypy__.internal_repr(s)
-
-    def test_splitlines_produces_strslices(self):
-        import __pypy__
-        l = ("X" * 100 + "\n" + "Y" * 100).splitlines()
-        assert "W_StringSliceObject" in __pypy__.internal_repr(l[0])
-        assert "W_StringSliceObject" in __pypy__.internal_repr(l[1])
-
-    def test_count_does_not_force(self):
-        def slice(s): return (s*3)[len(s):-len(s)]
-        s = slice("X" * 100 + "\n" + "Y" * 100)
-        assert s.count("X") == 100
-        assert s.count("Y") == 100
-        assert self.not_forced(s)
-
-    def test_extended_slice(self):
-        import __pypy__
-        def slice1(s): return (s*3)[len(s):-len(s)]
-        s = slice1('0123456789' * 20)
-        assert len(s) == 200
-        assert self.not_forced(s)
-        t = s[::-1]
-        assert t == '9876543210' * 20
-        assert not self.not_forced(t)
-        u = s[slice(10, 20)]
-        assert self.not_forced(u)
-        assert u == '0123456789'
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.