Mercurial > cpython-lru_cache-weakref
diff Objects/stringobject.c @ 38292:e15b14c7fa14 legacy-trunk
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)
| author | Fredrik Lundh <fredrik@pythonware.com> |
|---|---|
| date | Thu, 25 May 2006 15:49:45 +0000 |
| parents | ad1e2438cfaa |
| children | 41768de17ead |
line wrap: on
line diff
--- a/Objects/stringobject.c Thu May 25 15:22:03 2006 +0000 +++ b/Objects/stringobject.c Thu May 25 15:49:45 2006 +0000 @@ -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); + 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); } @@ -2067,14 +2069,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); + for (i = 0; i < n; i++) { - char c = Py_CHARMASK(s[i]); + int c = Py_CHARMASK(s[i]); if (islower(c)) s[i] = _toupper(c); }
