Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
gh-117431: Adapt str.{start,end}swith to use the METH_FASTCALL calling convention#117466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
c038634a9d31722ce5be66c95a0d8fe04aec2ce49eFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Improve the performance of :meth:`str.startswith` and :meth:`str.endswith` | ||
| by adapting them to the :c:macro:`METH_FASTCALL` calling convention. |
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -13021,40 +13021,41 @@ unicode_zfill_impl(PyObject *self, Py_ssize_t width) | ||
| return u; | ||
| } | ||
| /*[clinic input] | ||
| @text_signature "($self, prefix[, start[, end]], /)" | ||
| str.startswith as unicode_startswith | ||
| prefix as subobj: object | ||
| A string or a tuple of strings to try. | ||
| start: slice_index(accept={int, NoneType}, c_default='0') = None | ||
| Optional start position. Default: start of the string. | ||
| end: slice_index(accept={int, NoneType}, c_default='PY_SSIZE_T_MAX') = None | ||
| Optional stop position. Default: end of the string. | ||
| / | ||
| Return True if the string starts with the specified prefix, False otherwise. | ||
| [clinic start generated code]*/ | ||
| static PyObject * | ||
| unicode_startswith_impl(PyObject *self, PyObject *subobj, Py_ssize_t start, | ||
| Py_ssize_t end) | ||
| /*[clinic end generated code: output=4bd7cfd0803051d4 input=5f918b5f5f89d856]*/ | ||
| { | ||
| if (PyTuple_Check(subobj)) { | ||
| Py_ssize_t i; | ||
| for (i = 0; i < PyTuple_GET_SIZE(subobj); i++) { | ||
| PyObject *substring = PyTuple_GET_ITEM(subobj, i); | ||
| if (!PyUnicode_Check(substring)) { | ||
| PyErr_Format(PyExc_TypeError, | ||
| "tuple for startswith must only contain str, " | ||
| "not %.100s", | ||
| Py_TYPE(substring)->tp_name); | ||
| return NULL; | ||
| } | ||
| intresult = tailmatch(self, substring, start, end, -1); | ||
| if (result< 0) { | ||
| return NULL; | ||
| } | ||
| if (result) { | ||
| Py_RETURN_TRUE; | ||
| } | ||
| @@ -13068,47 +13069,41 @@ unicode_startswith(PyObject *self, | ||
| "a tuple of str, not %.100s", Py_TYPE(subobj)->tp_name); | ||
| return NULL; | ||
| } | ||
| intresult = tailmatch(self, subobj, start, end, -1); | ||
| if (result< 0) { | ||
| return NULL; | ||
| } | ||
| return PyBool_FromLong(result); | ||
| } | ||
| /*[clinic input] | ||
| @text_signature "($self, prefix[, start[, end]], /)" | ||
erlend-aasland marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| str.endswith as unicode_endswith = str.startswith | ||
| Return True if the string ends with the specified prefix, False otherwise. | ||
| [clinic start generated code]*/ | ||
| static PyObject * | ||
| unicode_endswith_impl(PyObject *self, PyObject *subobj, Py_ssize_t start, | ||
| Py_ssize_t end) | ||
| /*[clinic end generated code: output=cce6f8ceb0102ca9 input=82cd5ce9e7623646]*/ | ||
| { | ||
| if (PyTuple_Check(subobj)) { | ||
| Py_ssize_t i; | ||
| for (i = 0; i < PyTuple_GET_SIZE(subobj); i++) { | ||
| PyObject *substring = PyTuple_GET_ITEM(subobj, i); | ||
| if (!PyUnicode_Check(substring)) { | ||
| PyErr_Format(PyExc_TypeError, | ||
| "tuple for endswith must only contain str, " | ||
| "not %.100s", | ||
| Py_TYPE(substring)->tp_name); | ||
| return NULL; | ||
| } | ||
| intresult = tailmatch(self, substring, start, end, +1); | ||
| if (result< 0) { | ||
| return NULL; | ||
| } | ||
| if (result) { | ||
| Py_RETURN_TRUE; | ||
| } | ||
| @@ -13121,9 +13116,10 @@ unicode_endswith(PyObject *self, | ||
| "a tuple of str, not %.100s", Py_TYPE(subobj)->tp_name); | ||
| return NULL; | ||
| } | ||
| intresult = tailmatch(self, subobj, start, end, +1); | ||
| if (result< 0) { | ||
| return NULL; | ||
| } | ||
| return PyBool_FromLong(result); | ||
| } | ||
| @@ -13576,8 +13572,8 @@ static PyMethodDef unicode_methods[] = { | ||
| UNICODE_SWAPCASE_METHODDEF | ||
| UNICODE_TRANSLATE_METHODDEF | ||
| UNICODE_UPPER_METHODDEF | ||
| UNICODE_STARTSWITH_METHODDEF | ||
| UNICODE_ENDSWITH_METHODDEF | ||
| UNICODE_REMOVEPREFIX_METHODDEF | ||
| UNICODE_REMOVESUFFIX_METHODDEF | ||
| UNICODE_ISASCII_METHODDEF | ||