[Python-checkins] python/dist/src/Objects stringobject.c, 2.228,
2.229
rhettinger at users.sourceforge.net
rhettinger at users.sourceforge.net
Sun Feb 20 10:54:55 CET 2005
Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22296/Objects
Modified Files:
stringobject.c
Log Message:
* Beef-up tests for str.count().
* Speed-up str.count() by using memchr() to fly between first char matches.
Index: stringobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/stringobject.c,v
retrieving revision 2.228
retrieving revision 2.229
diff -u -d -r2.228 -r2.229
--- stringobject.c 20 Feb 2005 04:07:04 -0000 2.228
+++ stringobject.c 20 Feb 2005 09:54:52 -0000 2.229
@@ -2145,7 +2145,7 @@
static PyObject *
string_count(PyStringObject *self, PyObject *args)
{
- const char *s = PyString_AS_STRING(self), *sub;
+ const char *s = PyString_AS_STRING(self), *sub, *t;
int len = PyString_GET_SIZE(self), n;
int i = 0, last = INT_MAX;
int m, r;
@@ -2186,11 +2186,16 @@
} else {
i++;
}
+ if (i >= m)
+ break;
+ t = memchr(s+i, sub[0], m-i);
+ if (t == NULL)
+ break;
+ i = t - s;
}
return PyInt_FromLong((long) r);
}
-
PyDoc_STRVAR(swapcase__doc__,
"S.swapcase() -> string\n\
\n\
More information about the Python-checkins
mailing list