[Python-checkins] r46216 - python/trunk/Objects/stringobject.c
Jim Jewett
jimjjewett at gmail.com
Thu May 25 18:21:09 CEST 2006
On 5/25/06, fredrik.lundh <python-checkins at python.org> wrote:
> Author: fredrik.lundh
> Date: Thu May 25 17:49:45 2006
> New Revision: 46216
>
> Modified:
> python/trunk/Objects/stringobject.c
> Log:
> needforspeed: make new upper/lower work properly for single-character
> strings too... (thanks to georg brandl for spotting the exact problem
> faster than anyone else)
==============================================================================
> --- python/trunk/Objects/stringobject.c (original)
> +++ python/trunk/Objects/stringobject.c Thu May 25 17:49:45 2006
> @@ -2040,14 +2040,16 @@
> Py_ssize_t i, n = PyString_GET_SIZE(self);
> PyObject *newobj;
>
> - newobj = PyString_FromStringAndSize(PyString_AS_STRING(self), n);
> + newobj = PyString_FromStringAndSize(NULL, n);
> if (!newobj)
> return NULL;
>
> s = PyString_AS_STRING(newobj);
>
> + memcpy(s, PyString_AS_STRING(self), n);
Doesn't PyString_FromStringAndSize already fill newobj with a copy of
the current string?
> +
> for (i = 0; i < n; i++) {
> - char c = Py_CHARMASK(s[i]);
> + int c = Py_CHARMASK(s[i]);
> if (isupper(c))
> s[i] = _tolower(c);
> }
Do you want to check that any characters actually changed, and just
return an incremented self otherwise?
-jJ
More information about the Python-checkins
mailing list