diff options
author | Nikita Sobolev <mail@sobolevn.me> | 2023-11-04 09:59:46 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-04 09:59:46 (GMT) |
commit | a28a3967ab9a189122f895d51d2551f7b3a273b0 (patch) | |
tree | 228939ee7af431fd8ee289e3289e2d94807e962c | |
parent | 890ef1b035457fe5d0b0faf27a703c74c33e0141 (diff) | |
download | cpython-a28a3967ab9a189122f895d51d2551f7b3a273b0.zip cpython-a28a3967ab9a189122f895d51d2551f7b3a273b0.tar.gz cpython-a28a3967ab9a189122f895d51d2551f7b3a273b0.tar.bz2 |
gh-111666: Speed up `BaseExceptionGroup.{derive,split,subgroup}` (#111667)
-rw-r--r-- | Misc/NEWS.d/next/Core and Builtins/2023-11-03-01-23-48.gh-issue-111666.l8Q8G5.rst | 3 | ||||
-rw-r--r-- | Objects/exceptions.c | 26 |
2 files changed, 9 insertions, 20 deletions
diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-11-03-01-23-48.gh-issue-111666.l8Q8G5.rst b/Misc/NEWS.d/next/Core and Builtins/2023-11-03-01-23-48.gh-issue-111666.l8Q8G5.rst new file mode 100644 index 0000000..1d742a7 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2023-11-03-01-23-48.gh-issue-111666.l8Q8G5.rst @@ -0,0 +1,3 @@ +Speed up :meth:`BaseExceptionGroup.derive`, +:meth:`BaseExceptionGroup.subgroup`, and :meth:`BaseExceptionGroup.split` by +changing how they parse passed arguments. diff --git a/Objects/exceptions.c b/Objects/exceptions.c index e3e8e02..a685ed8 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -876,13 +876,9 @@ BaseExceptionGroup_str(PyBaseExceptionGroupObject *self) } static PyObject * -BaseExceptionGroup_derive(PyObject *self_, PyObject *args) +BaseExceptionGroup_derive(PyObject *self_, PyObject *excs) { PyBaseExceptionGroupObject *self = _PyBaseExceptionGroupObject_cast(self_); - PyObject *excs = NULL; - if (!PyArg_ParseTuple(args, "O", &excs)) { - return NULL; - } PyObject *init_args = PyTuple_Pack(2, self->msg, excs); if (!init_args) { return NULL; @@ -1176,13 +1172,8 @@ done: } static PyObject * -BaseExceptionGroup_split(PyObject *self, PyObject *args) +BaseExceptionGroup_split(PyObject *self, PyObject *matcher_value) { - PyObject *matcher_value = NULL; - if (!PyArg_UnpackTuple(args, "split", 1, 1, &matcher_value)) { - return NULL; - } - _exceptiongroup_split_matcher_type matcher_type; if (get_matcher_type(matcher_value, &matcher_type) < 0) { return NULL; @@ -1207,13 +1198,8 @@ BaseExceptionGroup_split(PyObject *self, PyObject *args) } static PyObject * -BaseExceptionGroup_subgroup(PyObject *self, PyObject *args) +BaseExceptionGroup_subgroup(PyObject *self, PyObject *matcher_value) { - PyObject *matcher_value = NULL; - if (!PyArg_UnpackTuple(args, "subgroup", 1, 1, &matcher_value)) { - return NULL; - } - _exceptiongroup_split_matcher_type matcher_type; if (get_matcher_type(matcher_value, &matcher_type) < 0) { return NULL; @@ -1488,9 +1474,9 @@ static PyMemberDef BaseExceptionGroup_members[] = { static PyMethodDef BaseExceptionGroup_methods[] = { {"__class_getitem__", (PyCFunction)Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")}, - {"derive", (PyCFunction)BaseExceptionGroup_derive, METH_VARARGS}, - {"split", (PyCFunction)BaseExceptionGroup_split, METH_VARARGS}, - {"subgroup", (PyCFunction)BaseExceptionGroup_subgroup, METH_VARARGS}, + {"derive", (PyCFunction)BaseExceptionGroup_derive, METH_O}, + {"split", (PyCFunction)BaseExceptionGroup_split, METH_O}, + {"subgroup", (PyCFunction)BaseExceptionGroup_subgroup, METH_O}, {NULL} }; |