Skip to content

Commit 1c327a4

Browse files
skirpichevcmaloneyvstinner
authored
gh-144650: Support vectorcall for _decimal.Decimal (#158207)
Co-authored-by: Cody Maloney <cmaloney@theoreticalchaos.com> Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent d9cfd30 commit 1c327a4

3 files changed

Lines changed: 51 additions & 6 deletions

File tree

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

‎Modules/_decimal/_decimal.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3313,6 +3313,7 @@ PyDec_FromObject(PyObject *v, PyObject *context)
33133313
}
33143314

33153315
/*[clinic input]
3316+
@vectorcall
33163317
@classmethod
33173318
_decimal.Decimal.__new__ as dec_new
33183319
@@ -3329,7 +3330,7 @@ trap is active.
33293330

33303331
static PyObject *
33313332
dec_new_impl(PyTypeObject *type, PyObject *value, PyObject *context)
3332-
/*[clinic end generated code: output=35f48a40c65625ba input=5f8a0892d3fcef80]*/
3333+
/*[clinic end generated code: output=35f48a40c65625ba input=0e5ca99183562cd9]*/
33333334
{
33343335
decimal_state *state = get_module_state_by_def(type);
33353336
CONTEXT_CHECK_VA(state, context);
@@ -6190,6 +6191,7 @@ static PyType_Slot dec_slots[] = {
61906191
{Py_tp_methods, dec_methods},
61916192
{Py_tp_getset, dec_getsets},
61926193
{Py_tp_new, dec_new},
6194+
{Py_tp_vectorcall, dec_vectorcall},
61936195

61946196
// Number protocol
61956197
{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)