From: Victor Stinner Date: Wed, 12 Oct 2011 22:18:12 +0000 (+0200) Subject: Optimize findchar() for PyUnicode_1BYTE_KIND: use memchr and memrchr X-Git-Tag: v3.3.0a1~1187 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9e7a1bcfd6737de148dd99c953e1d079ad3f239a;p=python Optimize findchar() for PyUnicode_1BYTE_KIND: use memchr and memrchr --- diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index e199a11f2d..5766237ed1 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -530,6 +530,14 @@ Py_LOCAL_INLINE(char *) findchar(void *s, int kind, { /* like wcschr, but doesn't stop at NULL characters */ Py_ssize_t i; + if (kind == 1) { + if (direction == 1) + return memchr(s, ch, size); +#ifdef HAVE_MEMRCHR + else + return memrchr(s, ch, size); +#endif + } if (direction == 1) { for(i = 0; i < size; i++) if (PyUnicode_READ(kind, s, i) == ch)