Skip to content

Commit a0723f1

Browse files
committed
gh-144650: support Vectorcall for _decimal.Decimal's
1 parent a000129 commit a0723f1

3 files changed

Lines changed: 53 additions & 7 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Use AC vectorcall support for the :class:`decimal.Decimal`. This offers
2+
~1.15x speedup on creation of small instances.

‎Modules/_decimal/_decimal.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
#define _PY_DEC_ROUND_GUARD (MPD_ROUND_GUARD-1)
5858
#endif
5959

60+
static PyType_Spec dec_spec;
61+
6062
#include "clinic/_decimal.c.h"
6163

6264
#define MPD_SPEC_VERSION "1.70" // Highest version of the spec this complies with
@@ -132,7 +134,6 @@ get_module_state(PyObject *mod)
132134
}
133135

134136
static struct PyModuleDef _decimal_module;
135-
static PyType_Spec dec_spec;
136137
static PyType_Spec context_spec;
137138

138139
static inline decimal_state *
@@ -3309,6 +3310,7 @@ PyDec_FromObject(PyObject *v, PyObject *context)
33093310
}
33103311

33113312
/*[clinic input]
3313+
@vectorcall
33123314
@classmethod
33133315
_decimal.Decimal.__new__ as dec_new
33143316
@@ -3325,7 +3327,7 @@ trap is active.
33253327

33263328
static PyObject *
33273329
dec_new_impl(PyTypeObject *type, PyObject *value, PyObject *context)
3328-
/*[clinic end generated code: output=35f48a40c65625ba input=5f8a0892d3fcef80]*/
3330+
/*[clinic end generated code: output=35f48a40c65625ba input=0e5ca99183562cd9]*/
33293331
{
33303332
decimal_state *state = get_module_state_by_def(type);
33313333
CONTEXT_CHECK_VA(state, context);
@@ -6186,6 +6188,7 @@ static PyType_Slot dec_slots[] = {
61866188
{Py_tp_methods, dec_methods},
61876189
{Py_tp_getset, dec_getsets},
61886190
{Py_tp_new, dec_new},
6191+
{Py_tp_vectorcall, dec_vectorcall},
61896192

61906193
// Number protocol
61916194
{Py_nb_add, nm_mpd_qadd},

‎Modules/_decimal/clinic/_decimal.c.h‎

Lines changed: 46 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)