Mercurial > cpython-lru_cache-weakref
diff Objects/stringobject.c @ 23051:19ea00feda33 legacy-trunk
Return the orginal string only if it's a real str or unicode
instance, otherwise make a copy.
| author | Walter Dörwald <walter@livinglogic.de> |
|---|---|
| date | Mon, 15 Apr 2002 18:42:15 +0000 |
| parents | 769e0a538e54 |
| children | e639e34ef901 |
line wrap: on
line diff
--- a/Objects/stringobject.c Mon Apr 15 18:41:31 2002 +0000 +++ b/Objects/stringobject.c Mon Apr 15 18:42:15 2002 +0000 @@ -2401,8 +2401,15 @@ return NULL; if (PyString_GET_SIZE(self) >= width) { - Py_INCREF(self); - return (PyObject*) self; + if (PyString_CheckExact(self)) { + Py_INCREF(self); + return (PyObject*) self; + } + else + return PyString_FromStringAndSize( + PyString_AS_STRING(self), + PyString_GET_SIZE(self) + ); } fill = width - PyString_GET_SIZE(self);
