Skip to content

Commit 6ca1abb

Browse files
committed
tmp
1 parent f7acd60 commit 6ca1abb

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

Objects/unicodeobject.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,21 @@ unicode_fill_invalid(PyObject *unicode, Py_ssize_t old_length)
11391139
}
11401140
#endif
11411141

1142+
static PyObject*
1143+
resize_copy(PyObject *unicode, Py_ssize_t length)
1144+
{
1145+
Py_ssize_t copy_length;
1146+
PyObject *copy;
1147+
1148+
copy = PyUnicode_New(length, PyUnicode_MAX_CHAR_VALUE(unicode));
1149+
if (copy == NULL)
1150+
return NULL;
1151+
1152+
copy_length = Py_MIN(length, PyUnicode_GET_LENGTH(unicode));
1153+
_PyUnicode_FastCopyCharacters(copy, 0, unicode, 0, copy_length);
1154+
return copy;
1155+
}
1156+
11421157
static PyObject*
11431158
resize_compact(PyObject *unicode, Py_ssize_t length)
11441159
{
@@ -1150,7 +1165,9 @@ resize_compact(PyObject *unicode, Py_ssize_t length)
11501165
Py_ssize_t old_length = _PyUnicode_LENGTH(unicode);
11511166
#endif
11521167

1153-
assert(unicode_modifiable(unicode));
1168+
if (!unicode_modifiable(unicode)) {
1169+
return resize_copy(unicode, length);
1170+
}
11541171
assert(PyUnicode_IS_COMPACT(unicode));
11551172

11561173
char_size = PyUnicode_KIND(unicode);
@@ -1250,21 +1267,6 @@ resize_inplace(PyObject *unicode, Py_ssize_t length)
12501267
return 0;
12511268
}
12521269

1253-
static PyObject*
1254-
resize_copy(PyObject *unicode, Py_ssize_t length)
1255-
{
1256-
Py_ssize_t copy_length;
1257-
PyObject *copy;
1258-
1259-
copy = PyUnicode_New(length, PyUnicode_MAX_CHAR_VALUE(unicode));
1260-
if (copy == NULL)
1261-
return NULL;
1262-
1263-
copy_length = Py_MIN(length, PyUnicode_GET_LENGTH(unicode));
1264-
_PyUnicode_FastCopyCharacters(copy, 0, unicode, 0, copy_length);
1265-
return copy;
1266-
}
1267-
12681270
static const char*
12691271
unicode_kind_name(PyObject *unicode)
12701272
{

0 commit comments

Comments
 (0)