@@ -9272,24 +9272,23 @@ tailmatch(PyObject *self,
9272
9272
else
9273
9273
offset = start ;
9274
9274
9275
- if (PyUnicode_READ (kind_self , data_self , offset ) ==
9276
- PyUnicode_READ (kind_sub , data_sub , 0 ) &&
9277
- PyUnicode_READ (kind_self , data_self , offset + end_sub ) ==
9278
- PyUnicode_READ (kind_sub , data_sub , end_sub )) {
9275
+ int last_character_matches = PyUnicode_READ (kind_self , data_self , offset + end_sub ) ==
9276
+ PyUnicode_READ (kind_sub , data_sub , end_sub );
9277
+
9278
+ if (last_character_matches ) {
9279
+ if (end_sub == 0 )
9280
+ return 1 ;
9279
9281
/* If both are of the same kind, memcmp is sufficient */
9280
9282
if (kind_self == kind_sub ) {
9281
- return ! memcmp ((char * )data_self +
9282
- (offset * PyUnicode_KIND (substring )),
9283
- data_sub ,
9284
- PyUnicode_GET_LENGTH (substring ) *
9285
- PyUnicode_KIND (substring ));
9283
+ return ! memcmp ((char * )data_self + (offset * kind_sub ),
9284
+ data_sub , end_sub * kind_sub );
9286
9285
}
9287
9286
/* otherwise we have to compare each character by first accessing it */
9288
9287
else {
9289
9288
/* We do not need to compare 0 and len(substring)-1 because
9290
9289
the if statement above ensured already that they are equal
9291
9290
when we end up here. */
9292
- for (i = 1 ; i < end_sub ; ++ i ) {
9291
+ for (i = 0 ; i < end_sub ; ++ i ) {
9293
9292
if (PyUnicode_READ (kind_self , data_self , offset + i ) !=
9294
9293
PyUnicode_READ (kind_sub , data_sub , i ))
9295
9294
return 0 ;
0 commit comments