]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-97982: Remove asciilib_count() (#98164)
authorVictor Stinner <vstinner@python.org>
Tue, 11 Oct 2022 15:59:58 +0000 (17:59 +0200)
committerGitHub <noreply@github.com>
Tue, 11 Oct 2022 15:59:58 +0000 (17:59 +0200)
asciilib_count() is the same than ucs1lib_count(): the code is not
specialized for ASCII strings, so it's not worth it to have a
separated function. Remove asciilib_count() function.

Objects/stringlib/count.h
Objects/unicodeobject.c

index f48500bf561f2c23944b9a6158da8d89d3ce1c65..e20edcd104b1751daa118d17cafb75dc4f13a10d 100644 (file)
@@ -4,6 +4,11 @@
 #error must include "stringlib/fastsearch.h" before including this module
 #endif
 
+// gh-97982: Implementing asciilib_count() is not worth it, FASTSEARCH() does
+// not specialize the code for ASCII strings. Use ucs1lib_count() for ASCII and
+// UCS1 strings: it's the same than asciilib_count().
+#if !STRINGLIB_IS_UNICODE || STRINGLIB_MAX_CHAR > 0x7Fu
+
 Py_LOCAL_INLINE(Py_ssize_t)
 STRINGLIB(count)(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
                 const STRINGLIB_CHAR* sub, Py_ssize_t sub_len,
@@ -24,4 +29,4 @@ STRINGLIB(count)(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
     return count;
 }
 
-
+#endif
index bd169ed714212ddf9ea2b4f5eb68014d1ac39976..51e660afba083af39f0158cc098027d86e45c599 100644 (file)
@@ -9000,16 +9000,10 @@ PyUnicode_Count(PyObject *str,
 
     switch (kind1) {
     case PyUnicode_1BYTE_KIND:
-        if (PyUnicode_IS_ASCII(str) && PyUnicode_IS_ASCII(substr))
-            result = asciilib_count(
-                ((const Py_UCS1*)buf1) + start, end - start,
-                buf2, len2, PY_SSIZE_T_MAX
-                );
-        else
-            result = ucs1lib_count(
-                ((const Py_UCS1*)buf1) + start, end - start,
-                buf2, len2, PY_SSIZE_T_MAX
-                );
+        result = ucs1lib_count(
+            ((const Py_UCS1*)buf1) + start, end - start,
+            buf2, len2, PY_SSIZE_T_MAX
+            );
         break;
     case PyUnicode_2BYTE_KIND:
         result = ucs2lib_count(
@@ -9904,10 +9898,7 @@ anylib_count(int kind, PyObject *sstr, const void* sbuf, Py_ssize_t slen,
 {
     switch (kind) {
     case PyUnicode_1BYTE_KIND:
-        if (PyUnicode_IS_ASCII(sstr) && PyUnicode_IS_ASCII(str1))
-            return asciilib_count(sbuf, slen, buf1, len1, maxcount);
-        else
-            return ucs1lib_count(sbuf, slen, buf1, len1, maxcount);
+        return ucs1lib_count(sbuf, slen, buf1, len1, maxcount);
     case PyUnicode_2BYTE_KIND:
         return ucs2lib_count(sbuf, slen, buf1, len1, maxcount);
     case PyUnicode_4BYTE_KIND: