Skip to content

Commit

Permalink
Improve performance of startswith, endswith for strings and bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
eendebakpt committed Apr 1, 2024
1 parent 9dae05e commit 8670190
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Objects/stringlib/find.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ STRINGLIB(parse_args_finds)(const char * function_name, PyObject *args,
Py_ssize_t tmp_start = 0;
Py_ssize_t tmp_end = PY_SSIZE_T_MAX;
PyObject *obj_start=Py_None, *obj_end=Py_None;

if (PyTuple_GET_SIZE(args) == 1) {
// fast path
*start = tmp_start;
*end = tmp_end;
*subobj = Py_NewRef(PyTuple_GET_ITEM(args, 0));
return 1;
}

char format[FORMAT_BUFFER_SIZE] = "O|OO:";
size_t len = strlen(format);

Expand Down

0 comments on commit 8670190

Please sign in to comment.