mirror of
https://github.com/python/cpython.git
synced 2025-12-11 11:31:05 +00:00
Issue #14478: Cache the hash of a Decimal in the C version.
This commit is contained in:
parent
9deb188799
commit
cc74b6ab14
1 changed files with 14 additions and 1 deletions
|
|
@ -60,6 +60,7 @@
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
|
Py_hash_t hash;
|
||||||
mpd_t dec;
|
mpd_t dec;
|
||||||
mpd_uint_t data[_Py_DEC_MINALLOC];
|
mpd_uint_t data[_Py_DEC_MINALLOC];
|
||||||
} PyDecObject;
|
} PyDecObject;
|
||||||
|
|
@ -1805,6 +1806,8 @@ PyDecType_New(PyTypeObject *type)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dec->hash = -1;
|
||||||
|
|
||||||
MPD(dec)->flags = MPD_STATIC|MPD_STATIC_DATA;
|
MPD(dec)->flags = MPD_STATIC|MPD_STATIC_DATA;
|
||||||
MPD(dec)->exp = 0;
|
MPD(dec)->exp = 0;
|
||||||
MPD(dec)->digits = 0;
|
MPD(dec)->digits = 0;
|
||||||
|
|
@ -4210,7 +4213,7 @@ dec_floor(PyObject *self, PyObject *dummy UNUSED)
|
||||||
|
|
||||||
/* Always uses the module context */
|
/* Always uses the module context */
|
||||||
static Py_hash_t
|
static Py_hash_t
|
||||||
dec_hash(PyObject *v)
|
_dec_hash(PyDecObject *v)
|
||||||
{
|
{
|
||||||
#if defined(CONFIG_64) && _PyHASH_BITS == 61
|
#if defined(CONFIG_64) && _PyHASH_BITS == 61
|
||||||
/* 2**61 - 1 */
|
/* 2**61 - 1 */
|
||||||
|
|
@ -4323,6 +4326,16 @@ malloc_error:
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Py_hash_t
|
||||||
|
dec_hash(PyDecObject *self)
|
||||||
|
{
|
||||||
|
if (self->hash == -1) {
|
||||||
|
self->hash = _dec_hash(self);
|
||||||
|
}
|
||||||
|
|
||||||
|
return self->hash;
|
||||||
|
}
|
||||||
|
|
||||||
/* __reduce__ */
|
/* __reduce__ */
|
||||||
static PyObject *
|
static PyObject *
|
||||||
dec_reduce(PyObject *self, PyObject *dummy UNUSED)
|
dec_reduce(PyObject *self, PyObject *dummy UNUSED)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue