[Python-checkins] cpython (3.5): Issue #23573: Restored optimization of bytes.rfind() and bytearray.rfind()

serhiy.storchaka python-checkins at python.org
Mon Jul 20 21:59:09 CEST 2015


https://hg.python.org/cpython/rev/311a4d28631b
changeset:   96964:311a4d28631b
branch:      3.5
parent:      96962:0bb44313842a
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Mon Jul 20 22:58:02 2015 +0300
summary:
  Issue #23573: Restored optimization of bytes.rfind() and bytearray.rfind()
for single-byte argument on Linux.

files:
  Misc/NEWS                 |   3 +++
  Objects/bytearrayobject.c |  10 +++++++---
  Objects/bytesobject.c     |  10 +++++++---
  3 files changed, 17 insertions(+), 6 deletions(-)


diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@
 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.
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -1171,12 +1171,16 @@
     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;
     }
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -1815,12 +1815,16 @@
     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;
     }

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list