]> granicus.if.org Git - python/commitdiff
Optimize findchar() for PyUnicode_1BYTE_KIND: use memchr and memrchr
authorVictor Stinner <victor.stinner@haypocalc.com>
Wed, 12 Oct 2011 22:18:12 +0000 (00:18 +0200)
committerVictor Stinner <victor.stinner@haypocalc.com>
Wed, 12 Oct 2011 22:18:12 +0000 (00:18 +0200)
Objects/unicodeobject.c

index e199a11f2d03c1b018bc2c63fbb193e44185ac9d..5766237ed15735442ec19f25cdbad71ca1348edf 100644 (file)
@@ -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)