[Python-checkins] cpython: Cleanup PyUnicode_Contains()
victor.stinner
python-checkins at python.org
Sun Apr 14 19:31:49 CEST 2013
http://hg.python.org/cpython/rev/a88310d86455
changeset: 83388:a88310d86455
user: Victor Stinner <victor.stinner at gmail.com>
date: Sun Apr 14 19:22:47 2013 +0200
summary:
Cleanup PyUnicode_Contains()
* No need to double-check that strings are ready: test already done by
PyUnicode_FromObject()
* Remove useless kind variable (use kind1 instead)
files:
Objects/unicodeobject.c | 17 ++++++-----------
1 files changed, 6 insertions(+), 11 deletions(-)
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -10532,7 +10532,7 @@
PyUnicode_Contains(PyObject *container, PyObject *element)
{
PyObject *str, *sub;
- int kind1, kind2, kind;
+ int kind1, kind2;
void *buf1, *buf2;
Py_ssize_t len1, len2;
int result;
@@ -10551,23 +10551,18 @@
Py_DECREF(sub);
return -1;
}
- if (PyUnicode_READY(sub) == -1 || PyUnicode_READY(str) == -1) {
- Py_DECREF(sub);
- Py_DECREF(str);
- }
kind1 = PyUnicode_KIND(str);
kind2 = PyUnicode_KIND(sub);
- kind = kind1;
buf1 = PyUnicode_DATA(str);
buf2 = PyUnicode_DATA(sub);
- if (kind2 != kind) {
- if (kind2 > kind) {
+ if (kind2 != kind1) {
+ if (kind2 > kind1) {
Py_DECREF(sub);
Py_DECREF(str);
return 0;
}
- buf2 = _PyUnicode_AsKind(sub, kind);
+ buf2 = _PyUnicode_AsKind(sub, kind1);
}
if (!buf2) {
Py_DECREF(sub);
@@ -10577,7 +10572,7 @@
len1 = PyUnicode_GET_LENGTH(str);
len2 = PyUnicode_GET_LENGTH(sub);
- switch (kind) {
+ switch (kind1) {
case PyUnicode_1BYTE_KIND:
result = ucs1lib_find(buf1, len1, buf2, len2, 0) != -1;
break;
@@ -10595,7 +10590,7 @@
Py_DECREF(str);
Py_DECREF(sub);
- if (kind2 != kind)
+ if (kind2 != kind1)
PyMem_Free(buf2);
return result;
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list