Skip to content

Commit df3a6d9

Browse files
authored
gh-97982: Remove asciilib_count() (#98164)
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.
1 parent 7ec2e27 commit df3a6d9

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

Objects/stringlib/count.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
#error must include "stringlib/fastsearch.h" before including this module
55
#endif
66

7+
// gh-97982: Implementing asciilib_count() is not worth it, FASTSEARCH() does
8+
// not specialize the code for ASCII strings. Use ucs1lib_count() for ASCII and
9+
// UCS1 strings: it's the same than asciilib_count().
10+
#if !STRINGLIB_IS_UNICODE || STRINGLIB_MAX_CHAR > 0x7Fu
11+
712
Py_LOCAL_INLINE(Py_ssize_t)
813
STRINGLIB(count)(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
914
const STRINGLIB_CHAR* sub, Py_ssize_t sub_len,
@@ -24,4 +29,4 @@ STRINGLIB(count)(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
2429
return count;
2530
}
2631

27-
32+
#endif

Objects/unicodeobject.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9000,16 +9000,10 @@ PyUnicode_Count(PyObject *str,
90009000

90019001
switch (kind1) {
90029002
case PyUnicode_1BYTE_KIND:
9003-
if (PyUnicode_IS_ASCII(str) && PyUnicode_IS_ASCII(substr))
9004-
result = asciilib_count(
9005-
((const Py_UCS1*)buf1) + start, end - start,
9006-
buf2, len2, PY_SSIZE_T_MAX
9007-
);
9008-
else
9009-
result = ucs1lib_count(
9010-
((const Py_UCS1*)buf1) + start, end - start,
9011-
buf2, len2, PY_SSIZE_T_MAX
9012-
);
9003+
result = ucs1lib_count(
9004+
((const Py_UCS1*)buf1) + start, end - start,
9005+
buf2, len2, PY_SSIZE_T_MAX
9006+
);
90139007
break;
90149008
case PyUnicode_2BYTE_KIND:
90159009
result = ucs2lib_count(
@@ -9904,10 +9898,7 @@ anylib_count(int kind, PyObject *sstr, const void* sbuf, Py_ssize_t slen,
99049898
{
99059899
switch (kind) {
99069900
case PyUnicode_1BYTE_KIND:
9907-
if (PyUnicode_IS_ASCII(sstr) && PyUnicode_IS_ASCII(str1))
9908-
return asciilib_count(sbuf, slen, buf1, len1, maxcount);
9909-
else
9910-
return ucs1lib_count(sbuf, slen, buf1, len1, maxcount);
9901+
return ucs1lib_count(sbuf, slen, buf1, len1, maxcount);
99119902
case PyUnicode_2BYTE_KIND:
99129903
return ucs2lib_count(sbuf, slen, buf1, len1, maxcount);
99139904
case PyUnicode_4BYTE_KIND:

0 commit comments

Comments
 (0)