@@ -320,19 +320,19 @@ dictkeys_decref(PyDictKeysObject *dk)
320
320
static inline Py_ssize_t
321
321
dictkeys_get_index (const PyDictKeysObject * keys , Py_ssize_t i )
322
322
{
323
- Py_ssize_t s = DK_SIZE (keys );
323
+ int log2size = DK_LOG_SIZE (keys );
324
324
Py_ssize_t ix ;
325
325
326
- if (s <= 0xff ) {
326
+ if (log2size < 8 ) {
327
327
const int8_t * indices = (const int8_t * )(keys -> dk_indices );
328
328
ix = indices [i ];
329
329
}
330
- else if (s <= 0xffff ) {
330
+ else if (log2size < 16 ) {
331
331
const int16_t * indices = (const int16_t * )(keys -> dk_indices );
332
332
ix = indices [i ];
333
333
}
334
334
#if SIZEOF_VOID_P > 4
335
- else if (s > 0xffffffff ) {
335
+ else if (log2size >= 32 ) {
336
336
const int64_t * indices = (const int64_t * )(keys -> dk_indices );
337
337
ix = indices [i ];
338
338
}
@@ -349,23 +349,23 @@ dictkeys_get_index(const PyDictKeysObject *keys, Py_ssize_t i)
349
349
static inline void
350
350
dictkeys_set_index (PyDictKeysObject * keys , Py_ssize_t i , Py_ssize_t ix )
351
351
{
352
- Py_ssize_t s = DK_SIZE (keys );
352
+ int log2size = DK_LOG_SIZE (keys );
353
353
354
354
assert (ix >= DKIX_DUMMY );
355
355
assert (keys -> dk_version == 0 );
356
356
357
- if (s <= 0xff ) {
357
+ if (log2size < 8 ) {
358
358
int8_t * indices = (int8_t * )(keys -> dk_indices );
359
359
assert (ix <= 0x7f );
360
360
indices [i ] = (char )ix ;
361
361
}
362
- else if (s <= 0xffff ) {
362
+ else if (log2size < 16 ) {
363
363
int16_t * indices = (int16_t * )(keys -> dk_indices );
364
364
assert (ix <= 0x7fff );
365
365
indices [i ] = (int16_t )ix ;
366
366
}
367
367
#if SIZEOF_VOID_P > 4
368
- else if (s > 0xffffffff ) {
368
+ else if (log2size >= 32 ) {
369
369
int64_t * indices = (int64_t * )(keys -> dk_indices );
370
370
indices [i ] = ix ;
371
371
}
@@ -631,7 +631,7 @@ free_keys_object(PyDictKeysObject *keys)
631
631
// free_keys_object() must not be called after _PyDict_Fini()
632
632
assert (state -> keys_numfree != -1 );
633
633
#endif
634
- if (DK_SIZE (keys ) == PyDict_MINSIZE && state -> keys_numfree < PyDict_MAXFREELIST ) {
634
+ if (DK_LOG_SIZE (keys ) == PyDict_LOG_MINSIZE && state -> keys_numfree < PyDict_MAXFREELIST ) {
635
635
state -> keys_free_list [state -> keys_numfree ++ ] = keys ;
636
636
return ;
637
637
}
@@ -1196,7 +1196,7 @@ Internal routine used by dictresize() to build a hashtable of entries.
1196
1196
static void
1197
1197
build_indices (PyDictKeysObject * keys , PyDictKeyEntry * ep , Py_ssize_t n )
1198
1198
{
1199
- size_t mask = ( size_t ) DK_SIZE ( keys ) - 1 ;
1199
+ size_t mask = DK_MASK ( keys );
1200
1200
for (Py_ssize_t ix = 0 ; ix != n ; ix ++ , ep ++ ) {
1201
1201
Py_hash_t hash = ep -> me_hash ;
1202
1202
size_t i = hash & mask ;
@@ -1296,7 +1296,7 @@ dictresize(PyDictObject *mp, uint8_t log2_newsize)
1296
1296
// dictresize() must not be called after _PyDict_Fini()
1297
1297
assert (state -> keys_numfree != -1 );
1298
1298
#endif
1299
- if (DK_SIZE (oldkeys ) == PyDict_MINSIZE &&
1299
+ if (DK_LOG_SIZE (oldkeys ) == PyDict_LOG_MINSIZE &&
1300
1300
state -> keys_numfree < PyDict_MAXFREELIST )
1301
1301
{
1302
1302
state -> keys_free_list [state -> keys_numfree ++ ] = oldkeys ;
@@ -2555,7 +2555,7 @@ dict_merge(PyObject *a, PyObject *b, int override)
2555
2555
// If other is clean, combined, and just allocated, just clone it.
2556
2556
if (other -> ma_values == NULL &&
2557
2557
other -> ma_used == okeys -> dk_nentries &&
2558
- (DK_SIZE (okeys ) == PyDict_MINSIZE ||
2558
+ (DK_LOG_SIZE (okeys ) == PyDict_LOG_MINSIZE ||
2559
2559
USABLE_FRACTION (DK_SIZE (okeys )/2 ) < other -> ma_used )) {
2560
2560
PyDictKeysObject * keys = clone_combined_dict_keys (other );
2561
2561
if (keys == NULL ) {
0 commit comments