mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
Simplify PyUnicode_Copy()
USe PyUnicode_Copy() in fixup()
This commit is contained in:
parent
5bbe5e7c85
commit
87af4f2f3a
1 changed files with 7 additions and 26 deletions
|
@ -1921,7 +1921,7 @@ unicode_adjust_maxchar(PyObject **p_unicode)
|
||||||
PyObject*
|
PyObject*
|
||||||
PyUnicode_Copy(PyObject *unicode)
|
PyUnicode_Copy(PyObject *unicode)
|
||||||
{
|
{
|
||||||
Py_ssize_t size;
|
Py_ssize_t length;
|
||||||
PyObject *copy;
|
PyObject *copy;
|
||||||
void *data;
|
void *data;
|
||||||
|
|
||||||
|
@ -1932,28 +1932,15 @@ PyUnicode_Copy(PyObject *unicode)
|
||||||
if (PyUnicode_READY(unicode))
|
if (PyUnicode_READY(unicode))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
size = PyUnicode_GET_LENGTH(unicode);
|
length = PyUnicode_GET_LENGTH(unicode);
|
||||||
copy = PyUnicode_New(size, PyUnicode_MAX_CHAR_VALUE(unicode));
|
copy = PyUnicode_New(length, PyUnicode_MAX_CHAR_VALUE(unicode));
|
||||||
if (!copy)
|
if (!copy)
|
||||||
return NULL;
|
return NULL;
|
||||||
assert(PyUnicode_KIND(copy) == PyUnicode_KIND(unicode));
|
assert(PyUnicode_KIND(copy) == PyUnicode_KIND(unicode));
|
||||||
|
|
||||||
data = PyUnicode_DATA(unicode);
|
data = PyUnicode_DATA(unicode);
|
||||||
switch (PyUnicode_KIND(unicode))
|
Py_MEMCPY(PyUnicode_DATA(copy), PyUnicode_DATA(unicode),
|
||||||
{
|
length * PyUnicode_KIND(unicode));
|
||||||
case PyUnicode_1BYTE_KIND:
|
|
||||||
memcpy(PyUnicode_1BYTE_DATA(copy), data, size);
|
|
||||||
break;
|
|
||||||
case PyUnicode_2BYTE_KIND:
|
|
||||||
memcpy(PyUnicode_2BYTE_DATA(copy), data, sizeof(Py_UCS2) * size);
|
|
||||||
break;
|
|
||||||
case PyUnicode_4BYTE_KIND:
|
|
||||||
memcpy(PyUnicode_4BYTE_DATA(copy), data, sizeof(Py_UCS4) * size);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
assert(0);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
assert(_PyUnicode_CheckConsistency(copy, 1));
|
assert(_PyUnicode_CheckConsistency(copy, 1));
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
@ -9344,16 +9331,10 @@ fixup(PyObject *self,
|
||||||
PyObject *u;
|
PyObject *u;
|
||||||
Py_UCS4 maxchar_old, maxchar_new = 0;
|
Py_UCS4 maxchar_old, maxchar_new = 0;
|
||||||
|
|
||||||
if (PyUnicode_READY(self) == -1)
|
u = PyUnicode_Copy(self);
|
||||||
return NULL;
|
|
||||||
maxchar_old = PyUnicode_MAX_CHAR_VALUE(self);
|
|
||||||
u = PyUnicode_New(PyUnicode_GET_LENGTH(self),
|
|
||||||
maxchar_old);
|
|
||||||
if (u == NULL)
|
if (u == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
maxchar_old = PyUnicode_MAX_CHAR_VALUE(u);
|
||||||
Py_MEMCPY(PyUnicode_1BYTE_DATA(u), PyUnicode_1BYTE_DATA(self),
|
|
||||||
PyUnicode_GET_LENGTH(u) * PyUnicode_KIND(u));
|
|
||||||
|
|
||||||
/* fix functions return the new maximum character in a string,
|
/* fix functions return the new maximum character in a string,
|
||||||
if the kind of the resulting unicode object does not change,
|
if the kind of the resulting unicode object does not change,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue