[Python-checkins] cpython: Use directly unicode_empty instead of PyUnicode_New(0, 0)

victor.stinner python-checkins at python.org
Mon Dec 12 01:25:54 CET 2011


http://hg.python.org/cpython/rev/7d4051e620fe
changeset: 73934:7d4051e620fe
user: Victor Stinner <victor.stinner at haypocalc.com>
date: Sun Dec 11 21:44:00 2011 +0100
summary:
 Use directly unicode_empty instead of PyUnicode_New(0, 0)
files:
 Objects/unicodeobject.c | 18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -2122,8 +2122,10 @@
 PyUnicode_FromWideChar(register const wchar_t *w, Py_ssize_t size)
 {
 if (w == NULL) {
- if (size == 0)
- return PyUnicode_New(0, 0);
+ if (size == 0) {
+ Py_INCREF(unicode_empty);
+ return unicode_empty;
+ }
 PyErr_BadInternalCall();
 return NULL;
 }
@@ -4557,7 +4559,8 @@
 if (size == 0) {
 if (consumed)
 *consumed = 0;
- return (PyObject *)PyUnicode_New(0, 0);
+ Py_INCREF(unicode_empty);
+ return unicode_empty;
 }
 
 maxchar = utf8_max_char_size_and_char_count(s, size, &unicode_size);
@@ -12906,7 +12909,8 @@
 }
 
 if (slicelength <= 0) {
- return PyUnicode_New(0, 0);
+ Py_INCREF(unicode_empty);
+ return unicode_empty;
 } else if (start == 0 && step == 1 &&
 slicelength == PyUnicode_GET_LENGTH(self) &&
 PyUnicode_CheckExact(self)) {
@@ -13582,8 +13586,10 @@
 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|Oss:str",
 kwlist, &x, &encoding, &errors))
 return NULL;
- if (x == NULL)
- return PyUnicode_New(0, 0);
+ if (x == NULL) {
+ Py_INCREF(unicode_empty);
+ return unicode_empty;
+ }
 if (encoding == NULL && errors == NULL)
 return PyObject_Str(x);
 else
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /