Skip to content

Commit 2dabc73

Browse files
committed
Use anylib_count in unicode_count_impl
1 parent 8270d4b commit 2dabc73

1 file changed

Lines changed: 19 additions & 37 deletions

File tree

Objects/unicodeobject.c

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8964,6 +8964,21 @@ _PyUnicode_InsertThousandsGrouping(
89648964
return count;
89658965
}
89668966

8967+
static Py_ssize_t
8968+
anylib_count(int kind, PyObject *sstr, const void* sbuf, Py_ssize_t slen,
8969+
PyObject *str1, const void *buf1, Py_ssize_t len1, Py_ssize_t maxcount)
8970+
{
8971+
switch (kind) {
8972+
case PyUnicode_1BYTE_KIND:
8973+
return ucs1lib_count(sbuf, slen, buf1, len1, maxcount);
8974+
case PyUnicode_2BYTE_KIND:
8975+
return ucs2lib_count(sbuf, slen, buf1, len1, maxcount);
8976+
case PyUnicode_4BYTE_KIND:
8977+
return ucs4lib_count(sbuf, slen, buf1, len1, maxcount);
8978+
}
8979+
Py_UNREACHABLE();
8980+
}
8981+
89678982
static Py_ssize_t
89688983
unicode_count_impl(PyObject *str,
89698984
PyObject *substr,
@@ -8997,28 +9012,10 @@ unicode_count_impl(PyObject *str,
89979012
goto onError;
89989013
}
89999014

9000-
switch (kind1) {
9001-
case PyUnicode_1BYTE_KIND:
9002-
result = ucs1lib_count(
9003-
((const Py_UCS1*)buf1) + start, end - start,
9004-
buf2, len2, PY_SSIZE_T_MAX
9005-
);
9006-
break;
9007-
case PyUnicode_2BYTE_KIND:
9008-
result = ucs2lib_count(
9009-
((const Py_UCS2*)buf1) + start, end - start,
9010-
buf2, len2, PY_SSIZE_T_MAX
9011-
);
9012-
break;
9013-
case PyUnicode_4BYTE_KIND:
9014-
result = ucs4lib_count(
9015-
((const Py_UCS4*)buf1) + start, end - start,
9016-
buf2, len2, PY_SSIZE_T_MAX
9017-
);
9018-
break;
9019-
default:
9020-
Py_UNREACHABLE();
9021-
}
9015+
result = anylib_count(kind1,
9016+
str, buf1 + start, end - start,
9017+
substr, buf2, len2,
9018+
PY_SSIZE_T_MAX);
90229019

90239020
assert((kind2 != kind1) == (buf2 != PyUnicode_DATA(substr)));
90249021
if (kind2 != kind1)
@@ -9903,21 +9900,6 @@ anylib_find(int kind, PyObject *str1, const void *buf1, Py_ssize_t len1,
99039900
Py_UNREACHABLE();
99049901
}
99059902

9906-
static Py_ssize_t
9907-
anylib_count(int kind, PyObject *sstr, const void* sbuf, Py_ssize_t slen,
9908-
PyObject *str1, const void *buf1, Py_ssize_t len1, Py_ssize_t maxcount)
9909-
{
9910-
switch (kind) {
9911-
case PyUnicode_1BYTE_KIND:
9912-
return ucs1lib_count(sbuf, slen, buf1, len1, maxcount);
9913-
case PyUnicode_2BYTE_KIND:
9914-
return ucs2lib_count(sbuf, slen, buf1, len1, maxcount);
9915-
case PyUnicode_4BYTE_KIND:
9916-
return ucs4lib_count(sbuf, slen, buf1, len1, maxcount);
9917-
}
9918-
Py_UNREACHABLE();
9919-
}
9920-
99219903
static void
99229904
replace_1char_inplace(PyObject *u, Py_ssize_t pos,
99239905
Py_UCS4 u1, Py_UCS4 u2, Py_ssize_t maxcount)

0 commit comments

Comments
 (0)