diff options
author | Erlend E. Aasland <erlend@python.org> | 2024-04-12 07:40:55 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-12 07:40:55 (GMT) |
commit | deb921f85173a194afb4386553d85c3f99767ca1 (patch) | |
tree | c5f32d62bf1ad727f25f6e8b084876c32d8a96e2 /Objects/stringlib | |
parent | 49fc1414b52b31f6ad0408775d160ec0559c33bb (diff) | |
download | cpython-deb921f85173a194afb4386553d85c3f99767ca1.zip cpython-deb921f85173a194afb4386553d85c3f99767ca1.tar.gz cpython-deb921f85173a194afb4386553d85c3f99767ca1.tar.bz2 |
gh-117431: Adapt bytes and bytearray .find() and friends to Argument Clinic (#117502)
This change gives a significant speedup, as the METH_FASTCALL calling
convention is now used. The following bytes and bytearray methods are adapted:
- count()
- find()
- index()
- rfind()
- rindex()
Co-authored-by: Inada Naoki <songofacandy@gmail.com>
Diffstat (limited to 'Objects/stringlib')
-rw-r--r-- | Objects/stringlib/find.h | 47 |
1 files changed, 0 insertions, 47 deletions
diff --git a/Objects/stringlib/find.h b/Objects/stringlib/find.h index 509b929..c385718 100644 --- a/Objects/stringlib/find.h +++ b/Objects/stringlib/find.h @@ -70,50 +70,3 @@ STRINGLIB(contains_obj)(PyObject* str, PyObject* sub) } #endif /* STRINGLIB_WANT_CONTAINS_OBJ */ - -/* -This function is a helper for the "find" family (find, rfind, index, -rindex) and for count, startswith and endswith, because they all have -the same behaviour for the arguments. - -It does not touch the variables received until it knows everything -is ok. -*/ - -#define FORMAT_BUFFER_SIZE 50 - -Py_LOCAL_INLINE(int) -STRINGLIB(parse_args_finds)(const char * function_name, PyObject *args, - PyObject **subobj, - Py_ssize_t *start, Py_ssize_t *end) -{ - PyObject *tmp_subobj; - Py_ssize_t tmp_start = 0; - Py_ssize_t tmp_end = PY_SSIZE_T_MAX; - PyObject *obj_start=Py_None, *obj_end=Py_None; - char format[FORMAT_BUFFER_SIZE] = "O|OO:"; - size_t len = strlen(format); - - strncpy(format + len, function_name, FORMAT_BUFFER_SIZE - len - 1); - format[FORMAT_BUFFER_SIZE - 1] = '\0'; - - if (!PyArg_ParseTuple(args, format, &tmp_subobj, &obj_start, &obj_end)) - return 0; - - /* To support None in "start" and "end" arguments, meaning - the same as if they were not passed. - */ - if (obj_start != Py_None) - if (!_PyEval_SliceIndex(obj_start, &tmp_start)) - return 0; - if (obj_end != Py_None) - if (!_PyEval_SliceIndex(obj_end, &tmp_end)) - return 0; - - *start = tmp_start; - *end = tmp_end; - *subobj = tmp_subobj; - return 1; -} - -#undef FORMAT_BUFFER_SIZE |