@@ -10858,60 +10858,11 @@ unicode_count(PyObject *self, PyObject *args)
10858
10858
Py_ssize_t start = 0 ;
10859
10859
Py_ssize_t end = PY_SSIZE_T_MAX ;
10860
10860
PyObject * result ;
10861
- int kind1 , kind2 ;
10862
- const void * buf1 , * buf2 ;
10863
- Py_ssize_t len1 , len2 , iresult ;
10864
10861
10865
10862
if (!parse_args_finds_unicode ("count" , args , & substring , & start , & end ))
10866
10863
return NULL ;
10867
10864
10868
- kind1 = PyUnicode_KIND (self );
10869
- kind2 = PyUnicode_KIND (substring );
10870
- if (kind1 < kind2 )
10871
- return PyLong_FromLong (0 );
10872
-
10873
- len1 = PyUnicode_GET_LENGTH (self );
10874
- len2 = PyUnicode_GET_LENGTH (substring );
10875
- ADJUST_INDICES (start , end , len1 );
10876
- if (end - start < len2 )
10877
- return PyLong_FromLong (0 );
10878
-
10879
- buf1 = PyUnicode_DATA (self );
10880
- buf2 = PyUnicode_DATA (substring );
10881
- if (kind2 != kind1 ) {
10882
- buf2 = unicode_askind (kind2 , buf2 , len2 , kind1 );
10883
- if (!buf2 )
10884
- return NULL ;
10885
- }
10886
- switch (kind1 ) {
10887
- case PyUnicode_1BYTE_KIND :
10888
- iresult = ucs1lib_count (
10889
- ((const Py_UCS1 * )buf1 ) + start , end - start ,
10890
- buf2 , len2 , PY_SSIZE_T_MAX
10891
- );
10892
- break ;
10893
- case PyUnicode_2BYTE_KIND :
10894
- iresult = ucs2lib_count (
10895
- ((const Py_UCS2 * )buf1 ) + start , end - start ,
10896
- buf2 , len2 , PY_SSIZE_T_MAX
10897
- );
10898
- break ;
10899
- case PyUnicode_4BYTE_KIND :
10900
- iresult = ucs4lib_count (
10901
- ((const Py_UCS4 * )buf1 ) + start , end - start ,
10902
- buf2 , len2 , PY_SSIZE_T_MAX
10903
- );
10904
- break ;
10905
- default :
10906
- Py_UNREACHABLE ();
10907
- }
10908
-
10909
- result = PyLong_FromSsize_t (iresult );
10910
-
10911
- assert ((kind2 == kind1 ) == (buf2 == PyUnicode_DATA (substring )));
10912
- if (kind2 != kind1 )
10913
- PyMem_Free ((void * )buf2 );
10914
-
10865
+ result = PyLong_FromSsize_t (PyUnicode_Count (self , substring , start , end ));
10915
10866
return result ;
10916
10867
}
10917
10868
0 commit comments