Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve performance of startswith, endswith, count and find methods for strings and bytes.
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 = PyTuple_GET_ITEM(args, 0);
return 1;
}

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

Expand Down