mirror of
https://github.com/python/cpython.git
synced 2025-10-17 20:28:43 +00:00
gh-115754: Use Py_GetConstant(Py_CONSTANT_EMPTY_STR) (#125194)
Replace PyUnicode_New(0, 0), PyUnicode_FromString("") and PyUnicode_FromStringAndSize("", 0) with Py_GetConstant(Py_CONSTANT_EMPTY_STR).
This commit is contained in:
parent
6a39e96ab8
commit
b9a8ca0a6a
22 changed files with 35 additions and 35 deletions
|
@ -862,7 +862,7 @@ PyObject_Format(PyObject *obj, PyObject *format_spec)
|
|||
|
||||
/* If no format_spec is provided, use an empty string */
|
||||
if (format_spec == NULL) {
|
||||
empty = PyUnicode_New(0, 0);
|
||||
empty = Py_GetConstant(Py_CONSTANT_EMPTY_STR);
|
||||
format_spec = empty;
|
||||
}
|
||||
|
||||
|
|
|
@ -154,7 +154,7 @@ BaseException_str(PyBaseExceptionObject *self)
|
|||
{
|
||||
switch (PyTuple_GET_SIZE(self->args)) {
|
||||
case 0:
|
||||
return PyUnicode_FromString("");
|
||||
return Py_GetConstant(Py_CONSTANT_EMPTY_STR);
|
||||
case 1:
|
||||
return PyObject_Str(PyTuple_GET_ITEM(self->args, 0));
|
||||
default:
|
||||
|
@ -3001,7 +3001,7 @@ UnicodeEncodeError_str(PyObject *self)
|
|||
|
||||
if (exc->object == NULL) {
|
||||
/* Not properly initialized. */
|
||||
return PyUnicode_FromString("");
|
||||
return Py_GetConstant(Py_CONSTANT_EMPTY_STR);
|
||||
}
|
||||
|
||||
/* Get reason and encoding as strings, which they might not be if
|
||||
|
@ -3123,7 +3123,7 @@ UnicodeDecodeError_str(PyObject *self)
|
|||
|
||||
if (exc->object == NULL) {
|
||||
/* Not properly initialized. */
|
||||
return PyUnicode_FromString("");
|
||||
return Py_GetConstant(Py_CONSTANT_EMPTY_STR);
|
||||
}
|
||||
|
||||
/* Get reason and encoding as strings, which they might not be if
|
||||
|
@ -3224,7 +3224,7 @@ UnicodeTranslateError_str(PyObject *self)
|
|||
|
||||
if (exc->object == NULL) {
|
||||
/* Not properly initialized. */
|
||||
return PyUnicode_FromString("");
|
||||
return Py_GetConstant(Py_CONSTANT_EMPTY_STR);
|
||||
}
|
||||
|
||||
/* Get reason as a string, which it might not be if it's been
|
||||
|
|
|
@ -73,7 +73,7 @@ Py_LOCAL_INLINE(PyObject *)
|
|||
SubString_new_object_or_empty(SubString *str)
|
||||
{
|
||||
if (str->str == NULL) {
|
||||
return PyUnicode_New(0, 0);
|
||||
return Py_GetConstant(Py_CONSTANT_EMPTY_STR);
|
||||
}
|
||||
return SubString_new_object(str);
|
||||
}
|
||||
|
@ -531,7 +531,7 @@ render_field(PyObject *fieldobj, SubString *format_spec, _PyUnicodeWriter *write
|
|||
format_spec->start,
|
||||
format_spec->end);
|
||||
else
|
||||
format_spec_object = PyUnicode_New(0, 0);
|
||||
format_spec_object = Py_GetConstant(Py_CONSTANT_EMPTY_STR);
|
||||
if (format_spec_object == NULL)
|
||||
goto done;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue