bpo-35582: Argument Clinic: Optimize the "all boring objects" case. (GH-11520)
Use _PyArg_CheckPositional() and inlined code instead of
PyArg_UnpackTuple() and _PyArg_UnpackStack() if all parameters
are positional and use the "object" converter.
diff --git a/Objects/clinic/floatobject.c.h b/Objects/clinic/floatobject.c.h
index 741ca3b..4251d63 100644
--- a/Objects/clinic/floatobject.c.h
+++ b/Objects/clinic/floatobject.c.h
@@ -58,11 +58,14 @@
PyObject *return_value = NULL;
PyObject *o_ndigits = NULL;
- if (!_PyArg_UnpackStack(args, nargs, "__round__",
- 0, 1,
- &o_ndigits)) {
+ if (!_PyArg_CheckPositional("__round__", nargs, 0, 1)) {
goto exit;
}
+ if (nargs < 1) {
+ goto skip_optional;
+ }
+ o_ndigits = args[0];
+skip_optional:
return_value = float___round___impl(self, o_ndigits);
exit:
@@ -173,11 +176,14 @@
!_PyArg_NoKeywords("float", kwargs)) {
goto exit;
}
- if (!PyArg_UnpackTuple(args, "float",
- 0, 1,
- &x)) {
+ if (!_PyArg_CheckPositional("float", PyTuple_GET_SIZE(args), 0, 1)) {
goto exit;
}
+ if (PyTuple_GET_SIZE(args) < 1) {
+ goto skip_optional;
+ }
+ x = PyTuple_GET_ITEM(args, 0);
+skip_optional:
return_value = float_new_impl(type, x);
exit:
@@ -345,4 +351,4 @@
exit:
return return_value;
}
-/*[clinic end generated code: output=2631a60701a8f7d4 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=c183029d87dd41fa input=a9049054013a1b77]*/