summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2002-08-24 06:57:49 (GMT)
committerGuido van Rossum <guido@python.org>2002-08-24 06:57:49 (GMT)
commitbf935fde1550b768d9fb14cec230d1e79a5212c2 (patch)
treefc0aaddf9e0c7edd26df5b6e52c9a6e13a6ba678 /Objects
parent9d6897accc49f40414fbecafeb1c65562c6e4647 (diff)
downloadcpython-bf935fde1550b768d9fb14cec230d1e79a5212c2.zip
cpython-bf935fde1550b768d9fb14cec230d1e79a5212c2.tar.gz
cpython-bf935fde1550b768d9fb14cec230d1e79a5212c2.tar.bz2
string_contains(): speed up by avoiding function calls where
possible. This always called PyUnicode_Check() and PyString_Check(), at least one of which would call PyType_IsSubtype(). Also, this would call PyString_Size() on known string objects.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/stringobject.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index 0b79a06..8ae9407 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -991,24 +991,27 @@ string_contains(PyObject *a, PyObject *el)
{
const char *lhs, *rhs, *end;
int size;
+
+ if (!PyString_CheckExact(el)) {
#ifdef Py_USING_UNICODE
- if (PyUnicode_Check(el))
- return PyUnicode_Contains(a, el);
+ if (PyUnicode_Check(el))
+ return PyUnicode_Contains(a, el);
#endif
- if (!PyString_Check(el)) {
- PyErr_SetString(PyExc_TypeError,
- "'in <string>' requires string as left operand");
- return -1;
+ if (!PyString_Check(el)) {
+ PyErr_SetString(PyExc_TypeError,
+ "'in <string>' requires string as left operand");
+ return -1;
+ }
}
- size = PyString_Size(el);
+ size = PyString_GET_SIZE(el);
rhs = PyString_AS_STRING(el);
lhs = PyString_AS_STRING(a);
/* optimize for a single character */
if (size == 1)
- return memchr(lhs, *rhs, PyString_Size(a)) != NULL;
+ return memchr(lhs, *rhs, PyString_GET_SIZE(a)) != NULL;
- end = lhs + (PyString_Size(a) - size);
+ end = lhs + (PyString_GET_SIZE(a) - size);
while (lhs <= end) {
if (memcmp(lhs++, rhs, size) == 0)
return 1;