]> granicus.if.org Git - python/commitdiff
Issue #23573: Restored optimization of bytes.rfind() and bytearray.rfind()
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 20 Jul 2015 19:58:02 +0000 (22:58 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Mon, 20 Jul 2015 19:58:02 +0000 (22:58 +0300)
for single-byte argument on Linux.

Misc/NEWS
Objects/bytearrayobject.c
Objects/bytesobject.c

index 834ce388fecaf3f9f25f0a3f978afefdf3df6dad..286f2e2c031e4ba0aa9e9c450843a9323398ceba 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ Release date: 2015-07-26
 Core and Builtins
 -----------------
 
+- Issue #23573: Restored optimization of bytes.rfind() and bytearray.rfind()
+  for single-byte argument on Linux.
+
 - Issue #24569: Make PEP 448 dictionary evaluation more consistent.
 
 - Issue #24583: Fix crash when set is mutated while being updated.
index dae80d94245f6bd7cc3c5877f95dd5c418123e93..5647b57a52fa58ea23c2f9484e449466ec04be8a 100644 (file)
@@ -1171,12 +1171,16 @@ bytearray_find_internal(PyByteArrayObject *self, PyObject *args, int dir)
     ADJUST_INDICES(start, end, len);
     if (end - start < sub_len)
         res = -1;
-    /* Issue #23573: FIXME, windows has no memrchr() */
-    else if (sub_len == 1 && dir > 0) {
+    else if (sub_len == 1
+#ifndef HAVE_MEMRCHR
+            && dir > 0
+#endif
+    ) {
         unsigned char needle = *sub;
+        int mode = (dir > 0) ? FAST_SEARCH : FAST_RSEARCH;
         res = stringlib_fastsearch_memchr_1char(
             PyByteArray_AS_STRING(self) + start, end - start,
-            needle, needle, FAST_SEARCH);
+            needle, needle, mode);
         if (res >= 0)
             res += start;
     }
index 6a6e930f73a01fbfcdcdbeeeed4b583621325187..08275ad5ada1b6eb785cd6ead402f11b71bf322c 100644 (file)
@@ -1815,12 +1815,16 @@ bytes_find_internal(PyBytesObject *self, PyObject *args, int dir)
     ADJUST_INDICES(start, end, len);
     if (end - start < sub_len)
         res = -1;
-    /* Issue #23573: FIXME, windows has no memrchr() */
-    else if (sub_len == 1 && dir > 0) {
+    else if (sub_len == 1
+#ifndef HAVE_MEMRCHR
+            && dir > 0
+#endif
+    ) {
         unsigned char needle = *sub;
+        int mode = (dir > 0) ? FAST_SEARCH : FAST_RSEARCH;
         res = stringlib_fastsearch_memchr_1char(
             PyBytes_AS_STRING(self) + start, end - start,
-            needle, needle, FAST_SEARCH);
+            needle, needle, mode);
         if (res >= 0)
             res += start;
     }