@@ -771,66 +771,47 @@ tailmatch(const char *str, Py_ssize_t len, PyObject *substr,
771771
772772static PyObject *
773773_Py_bytes_tailmatch (const char * str , Py_ssize_t len ,
774- const char * function_name , PyObject * args ,
774+ const char * function_name , PyObject * subobj ,
775+ Py_ssize_t start , Py_ssize_t end ,
775776 int direction )
776777{
777- Py_ssize_t start = 0 ;
778- Py_ssize_t end = PY_SSIZE_T_MAX ;
779- PyObject * subobj = NULL ;
780- int result ;
781-
782- if (!stringlib_parse_args_finds (function_name , args , & subobj , & start , & end ))
783- return NULL ;
784778 if (PyTuple_Check (subobj )) {
785779 Py_ssize_t i ;
786780 for (i = 0 ; i < PyTuple_GET_SIZE (subobj ); i ++ ) {
787- result = tailmatch ( str , len , PyTuple_GET_ITEM (subobj , i ),
788- start , end , direction );
789- if (result == -1 )
781+ PyObject * item = PyTuple_GET_ITEM (subobj , i );
782+ int result = tailmatch ( str , len , item , start , end , direction );
783+ if (result < 0 ) {
790784 return NULL ;
785+ }
791786 else if (result ) {
792787 Py_RETURN_TRUE ;
793788 }
794789 }
795790 Py_RETURN_FALSE ;
796791 }
797- result = tailmatch (str , len , subobj , start , end , direction );
792+ int result = tailmatch (str , len , subobj , start , end , direction );
798793 if (result == -1 ) {
799- if (PyErr_ExceptionMatches (PyExc_TypeError ))
794+ if (PyErr_ExceptionMatches (PyExc_TypeError )) {
800795 PyErr_Format (PyExc_TypeError ,
801796 "%s first arg must be bytes or a tuple of bytes, "
802797 "not %s" ,
803798 function_name , Py_TYPE (subobj )-> tp_name );
799+ }
804800 return NULL ;
805801 }
806- else
807- return PyBool_FromLong (result );
802+ return PyBool_FromLong (result );
808803}
809804
810- PyDoc_STRVAR_shared (_Py_startswith__doc__ ,
811- "B.startswith(prefix[, start[, end]]) -> bool\n\
812- \n\
813- Return True if B starts with the specified prefix, False otherwise.\n\
814- With optional start, test B beginning at that position.\n\
815- With optional end, stop comparing B at that position.\n\
816- prefix can also be a tuple of bytes to try." );
817-
818805PyObject *
819- _Py_bytes_startswith (const char * str , Py_ssize_t len , PyObject * args )
806+ _Py_bytes_startswith (const char * str , Py_ssize_t len , PyObject * subobj ,
807+ Py_ssize_t start , Py_ssize_t end )
820808{
821- return _Py_bytes_tailmatch (str , len , "startswith" , args , -1 );
809+ return _Py_bytes_tailmatch (str , len , "startswith" , subobj , start , end , -1 );
822810}
823811
824- PyDoc_STRVAR_shared (_Py_endswith__doc__ ,
825- "B.endswith(suffix[, start[, end]]) -> bool\n\
826- \n\
827- Return True if B ends with the specified suffix, False otherwise.\n\
828- With optional start, test B beginning at that position.\n\
829- With optional end, stop comparing B at that position.\n\
830- suffix can also be a tuple of bytes to try." );
831-
832812PyObject *
833- _Py_bytes_endswith (const char * str , Py_ssize_t len , PyObject * args )
813+ _Py_bytes_endswith (const char * str , Py_ssize_t len , PyObject * subobj ,
814+ Py_ssize_t start , Py_ssize_t end )
834815{
835- return _Py_bytes_tailmatch (str , len , "endswith" , args , +1 );
816+ return _Py_bytes_tailmatch (str , len , "endswith" , subobj , start , end , +1 );
836817}
0 commit comments