Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Include/dictobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ PyAPI_FUNC(PyObject *) _PyDict_Pop(PyObject *, PyObject *, PyObject *);
PyObject *_PyDict_Pop_KnownHash(PyObject *, PyObject *, Py_hash_t, PyObject *);
PyObject *_PyDict_FromKeys(PyObject *, PyObject *, PyObject *);
#define _PyDict_HasSplitTable(d) ((d)->ma_values != NULL)

PyAPI_FUNC(Py_ssize_t) _PyDict_GetIndex(PyDictObject *, PyObject *, Py_hash_t);
PyAPI_FUNC(int) PyDict_ClearFreeList(void);
#endif

Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_ordered_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ def test_sizeof_exact(self):
size = support.calcobjsize
check = self.check_sizeof

basicsize = size('nQ2P' + '3PnPn2P') + calcsize('2nP2n')
basicsize = size('nQ2P' + '3Pn2P') + calcsize('4nI0P')

entrysize = calcsize('n2P')
p = calcsize('P')
Expand Down
8 changes: 4 additions & 4 deletions Lib/test/test_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -965,9 +965,9 @@ def inner():
# method-wrapper (descriptor object)
check({}.__iter__, size('2P'))
# dict
check({}, size('nQ2P') + calcsize('2nP2n') + 8 + (8*2//3)*calcsize('n2P'))
check({}, size('nQ2P') + calcsize('4nI0P') + 8 + (8*2//3)*calcsize('n2P'))
longdict = {1:1, 2:2, 3:3, 4:4, 5:5, 6:6, 7:7, 8:8}
check(longdict, size('nQ2P') + calcsize('2nP2n') + 16 + (16*2//3)*calcsize('n2P'))
check(longdict, size('nQ2P') + calcsize('4nI0P') + 16 + (16*2//3)*calcsize('n2P'))
# dictionary-keyview
check({}.keys(), size('P'))
# dictionary-valueview
Expand Down Expand Up @@ -1128,13 +1128,13 @@ def delx(self): del self.__x
'4P')
class newstyleclass(object): pass
# Separate block for PyDictKeysObject with 8 keys and 5 entries
check(newstyleclass, s + calcsize("2nP2n0P") + 8 + 5*calcsize("n2P"))
check(newstyleclass, s + calcsize("4nI0P") + 8 + 5*calcsize("n2P"))
# dict with shared keys
check(newstyleclass().__dict__, size('nQ2P') + 5*self.P)
o = newstyleclass()
o.a = o.b = o.c = o.d = o.e = o.f = o.g = o.h = 1
# Separate block for PyDictKeysObject with 16 keys and 10 entries
check(newstyleclass, s + calcsize("2nP2n0P") + 16 + 10*calcsize("n2P"))
check(newstyleclass, s + calcsize("4nI0P") + 16 + 10*calcsize("n2P"))
# dict with shared keys
check(newstyleclass().__dict__, size('nQ2P') + 10*self.P)
# unicode
Expand Down
21 changes: 9 additions & 12 deletions Objects/dict-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ typedef struct {
PyObject *me_value; /* This field is only meaningful for combined tables */
} PyDictKeyEntry;

/* dict_lookup_func() returns index of entry which can be used like DK_ENTRIES(dk)[index].
* -1 when no entry found, -3 when compare raises error.
*/
typedef Py_ssize_t (*dict_lookup_func)
(PyDictObject *mp, PyObject *key, Py_hash_t hash, PyObject **value_addr);

#define DKIX_EMPTY (-1)
#define DKIX_DUMMY (-2) /* Used internally */
#define DKIX_ERROR (-3)
Expand All @@ -25,6 +19,12 @@ struct _dictkeysobject {
/* Size of the hash table (dk_indices). It must be a power of 2. */
Py_ssize_t dk_size;

/* Number of usable entries in dk_entries. */
Py_ssize_t dk_usable;

/* Number of used entries in dk_entries. */
Py_ssize_t dk_nentries;

/* Function to lookup in the hash table (dk_indices):

- lookdict(): general-purpose, and may return DKIX_ERROR if (and
Expand All @@ -38,13 +38,10 @@ struct _dictkeysobject {
specialized for Unicode string keys that cannot be the <dummy> value.

- lookdict_split(): Version of lookdict() for split tables. */
dict_lookup_func dk_lookup;

/* Number of usable entries in dk_entries. */
Py_ssize_t dk_usable;
unsigned int dk_lookup: 8;

/* Number of used entries in dk_entries. */
Py_ssize_t dk_nentries;
/* Whether OrderedDict's cache is synchronized with dict table */
unsigned int dk_clean: 1;

/* Actual hash table of dk_size entries. It holds indices in dk_entries,
or DKIX_EMPTY(-1) or DKIX_DUMMY(-2).
Expand Down
Loading