8000 gh-117431: Improve performance of startswith and endswith by eendebakpt · Pull Request #117782 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
reduce churn
  • Loading branch information
eendebakpt committed Feb 10, 2025
commit abe35e8c3a53c8120bdffb395d18fbdfd1d99b68
7 changes: 2 additions & 5 deletions Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -9947,18 +9947,15 @@ tailmatch(PyObject *self,
PyUnicode_READ(kind_sub, data_sub, end_sub);

if (match_last) {
if (end_sub == 0) {
return 1;
}
/* If both are of the same kind, memcmp is sufficient */
if (kind_self == kind_sub) {
return ! memcmp((char *)data_self + (offset * kind_sub),
data_sub, end_sub * kind_sub);
}
/* otherwise we have to compare each character by first accessing it */
else {
/* We do not need to compare len(substring)-1 because the if
statement above ensured already that they are equal when we
/* We do not need to compare len(substring)-1 because the check on
match_last above ensured already that they are equal when we
end up here. */
for (i = 0; i < end_sub; ++i) {
if (PyUnicode_READ(kind_self, data_self, offset + i) !=
Expand Down
Loading
0