Author: walter.doerwald
Date: Sat Nov 3 23:44:11 2007
New Revision: 58835
Modified:
python/branches/py3k-pep3137/Objects/unicodeobject.c
Log:
Change PyUnicode_EncodeUTF8() to directly create a
PyString object instead of first allocating a PyBytes
object.
Modified: python/branches/py3k-pep3137/Objects/unicodeobject.c
==============================================================================
--- python/branches/py3k-pep3137/Objects/unicodeobject.c (original)
+++ python/branches/py3k-pep3137/Objects/unicodeobject.c Sat Nov 3
23:44:11 2007
@@ -1989,7 +1989,7 @@
#define MAX_SHORT_UNICHARS 300 /* largest size we'll do on the stack */
Py_ssize_t i; /* index into s of next input byte */
- PyObject *v, *result; /* result string object */
+ PyObject *result; /* result string object */
char *p; /* next free byte in output buffer */
Py_ssize_t nallocated; /* number of result bytes allocated */
Py_ssize_t nneeded; /* number of result bytes needed */
@@ -2004,7 +2004,7 @@
* turns out we need.
*/
nallocated = Py_SAFE_DOWNCAST(sizeof(stackbuf), size_t, int);
- v = NULL; /* will allocate after we're done */
+ result = NULL; /* will allocate after we're done */
p = stackbuf;
}
else {
@@ -2012,10 +2012,10 @@
nallocated = size * 4;
if (nallocated / 4 != size) /* overflow! */
return PyErr_NoMemory();
- v = PyBytes_FromStringAndSize(NULL, nallocated);
- if (v == NULL)
+ result = PyString_FromStringAndSize(NULL, nallocated);
+ if (result == NULL)
return NULL;
- p = PyBytes_AS_STRING(v);
+ p = PyString_AS_STRING(result);
}
for (i = 0; i < size;) {
@@ -2059,7 +2059,7 @@
}
}
- if (v == NULL) {
+ if (result == NULL) {
/* This was stack allocated. */
nneeded = p - stackbuf;
assert(nneeded <= nallocated);
@@ -2067,10 +2067,9 @@
}
else {
/* Cut back to size actually needed. */
- nneeded = p - PyBytes_AS_STRING(v);
+ nneeded = p - PyString_AS_STRING(result);
assert(nneeded <= nallocated);
- result = PyString_FromStringAndSize(PyBytes_AS_STRING(v), nneeded);
- Py_DECREF(v);
+ _PyString_Resize(&result, nneeded);
}
return result;
_______________________________________________
Python-3000-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000-checkins