[Python-checkins] r51494 - python/branches/p3yk-noslice/Objects/stringobject.c python/branches/p3yk-noslice/Objects/tupleobject.c python/branches/p3yk-noslice/Objects/unicodeobject.c
thomas.wouters
python-checkins at python.org
Wed Aug 23 00:37:36 CEST 2006
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*
More information about the Python-checkins
mailing list