mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
gh-133703: dict: fix calculate_log2_keysize() (GH-133809)
This commit is contained in:
parent
878e0fb8b4
commit
92337f666e
3 changed files with 6 additions and 7 deletions
|
@ -547,13 +547,13 @@ static inline uint8_t
|
|||
calculate_log2_keysize(Py_ssize_t minsize)
|
||||
{
|
||||
#if SIZEOF_LONG == SIZEOF_SIZE_T
|
||||
minsize = (minsize | PyDict_MINSIZE) - 1;
|
||||
return _Py_bit_length(minsize | (PyDict_MINSIZE-1));
|
||||
minsize = Py_MAX(minsize, PyDict_MINSIZE);
|
||||
return _Py_bit_length(minsize - 1);
|
||||
#elif defined(_MSC_VER)
|
||||
// On 64bit Windows, sizeof(long) == 4.
|
||||
minsize = (minsize | PyDict_MINSIZE) - 1;
|
||||
// On 64bit Windows, sizeof(long) == 4. We cannot use _Py_bit_length.
|
||||
minsize = Py_MAX(minsize, PyDict_MINSIZE);
|
||||
unsigned long msb;
|
||||
_BitScanReverse64(&msb, (uint64_t)minsize);
|
||||
_BitScanReverse64(&msb, (uint64_t)minsize - 1);
|
||||
return (uint8_t)(msb + 1);
|
||||
#else
|
||||
uint8_t log2_size;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue