
jimjjewett at gmail
Aug 23, 2006, 6:01 AM
Post #2 of 3
(166 views)
Permalink
|
|
Re: r51494 - python/branches/p3yk-noslice/Objects/stringobject.c python/branches/p3yk-noslice/Objects/tupleobject.c python/branches/p3yk-noslice/Objects/unicodeobject.c
[In reply to]
|
|
(1) I would personally prefer if (step == 1) { if (start == 0 && ...) {} else {} } I realize that the compiler can do this, but I like flagging "this is an odd special case" (2) Why the CheckExact? Is there a promise (even in py3K) that constructors won't return a subclass? I had thought that the question was only when/if to *guarantee* that the subclass would be used. If the intent is to guard against subclasses with a different internal layout, then it should come before the GET_SIZE macros. -jJ On 8/22/06, thomas.wouters <python-checkins [at] python> wrote: > Author: thomas.wouters > Date: Wed Aug 23 00:37:35 2006 > New Revision: 51494 > > Modified: > python/branches/p3yk-noslice/Objects/stringobject.c > python/branches/p3yk-noslice/Objects/tupleobject.c > python/branches/p3yk-noslice/Objects/unicodeobject.c > Log: > > Copy some of the special cases from normal slicing to extended slicing, for > general speedup. > > > > Modified: python/branches/p3yk-noslice/Objects/stringobject.c > ============================================================================== > --- python/branches/p3yk-noslice/Objects/stringobject.c (original) > +++ python/branches/p3yk-noslice/Objects/stringobject.c Wed Aug 23 00:37:35 2006 > @@ -1210,6 +1210,17 @@ > if (slicelength <= 0) { > return PyString_FromStringAndSize("", 0); > } > + else if (start == 0 && step == 1 && > + slicelength == PyString_GET_SIZE(self) && > + PyString_CheckExact(self)) { > + Py_INCREF(self); > + return (PyObject *)self; > + } > + else if (step == 1) { > + return PyString_FromStringAndSize( > + PyString_AS_STRING(self) + start, > + slicelength); > + } > else { > source_buf = PyString_AsString((PyObject*)self); > result_buf = (char *)PyMem_Malloc(slicelength); > > Modified: python/branches/p3yk-noslice/Objects/tupleobject.c > ============================================================================== > --- python/branches/p3yk-noslice/Objects/tupleobject.c (original) > +++ python/branches/p3yk-noslice/Objects/tupleobject.c Wed Aug 23 00:37:35 2006 > @@ -603,6 +603,12 @@ > if (slicelength <= 0) { > return PyTuple_New(0); > } > + else if (start == 0 && step == 1 && > + slicelength == PyTuple_GET_SIZE(self) && > + PyTuple_CheckExact(self)) { > + Py_INCREF(self); > + return (PyObject *)self; > + } > else { > result = PyTuple_New(slicelength); > if (!result) return NULL; > > Modified: python/branches/p3yk-noslice/Objects/unicodeobject.c > ============================================================================== > --- python/branches/p3yk-noslice/Objects/unicodeobject.c (original) > +++ python/branches/p3yk-noslice/Objects/unicodeobject.c Wed Aug 23 00:37:35 2006 > @@ -7083,6 +7083,12 @@ > > if (slicelength <= 0) { > return PyUnicode_FromUnicode(NULL, 0); > + } else if (start == 0 && step == 1 && slicelength == self->length && > + PyUnicode_CheckExact(self)) { > + Py_INCREF(self); > + return (PyObject *)self; > + } else if (step == 1) { > + return PyUnicode_FromUnicode(self->str + start, slicelength); > } else { > source_buf = PyUnicode_AS_UNICODE((PyObject*)self); > result_buf = (Py_UNICODE *)PyMem_MALLOC(slicelength* > _______________________________________________ > Python-checkins mailing list > Python-checkins [at] python > http://mail.python.org/mailman/listinfo/python-checkins > _______________________________________________ Python-checkins mailing list Python-checkins [at] python http://mail.python.org/mailman/listinfo/python-checkins
|