Skip to content

Commit

Permalink
Revert "pass keys_size to _PyDict_NewKeysForClass"
Browse files Browse the repository at this point in the history
This reverts commit add1804.
  • Loading branch information
iritkatriel committed Mar 23, 2024
1 parent 4f277d8 commit 010c64f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Include/internal/pycore_dict.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ typedef struct {
PyObject *me_value; /* This field is only meaningful for combined tables */
} PyDictUnicodeEntry;

extern PyDictKeysObject *_PyDict_NewKeysForClass(Py_ssize_t keys_size);
extern PyDictKeysObject *_PyDict_NewKeysForClass(void);
extern PyObject *_PyDict_FromKeys(PyObject *, PyObject *, PyObject *);

/* Gets a version number unique to the current state of the keys of dict, if possible.
Expand Down
6 changes: 3 additions & 3 deletions Objects/dictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -6522,18 +6522,18 @@ dictvalues_reversed(PyObject *self, PyObject *Py_UNUSED(ignored))
/* Returns NULL if cannot allocate a new PyDictKeysObject,
but does not set an error */
PyDictKeysObject *
_PyDict_NewKeysForClass(Py_ssize_t keys_size)
_PyDict_NewKeysForClass(void)
{
PyInterpreterState *interp = _PyInterpreterState_GET();
PyDictKeysObject *keys = new_keys_object(
interp, estimate_log2_keysize(keys_size), 1);
interp, NEXT_LOG2_SHARED_KEYS_MAX_SIZE, 1);
if (keys == NULL) {
PyErr_Clear();
}
else {
assert(keys->dk_nentries == 0);
/* Set to max size+1 as it will shrink by one before each new object */
keys->dk_usable = keys_size;
keys->dk_usable = SHARED_KEYS_MAX_SIZE;
keys->dk_kind = DICT_KEYS_SPLIT;
}
return keys;
Expand Down
8 changes: 1 addition & 7 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -7760,12 +7760,6 @@ type_ready_set_new(PyTypeObject *type, int rerunbuiltin)
return 0;
}

static Py_ssize_t
expected_number_of_shared_keys(PyTypeObject *type)
{
return SHARED_KEYS_MAX_SIZE;
}

static int
type_ready_managed_dict(PyTypeObject *type)
{
Expand All @@ -7781,7 +7775,7 @@ type_ready_managed_dict(PyTypeObject *type)
}
PyHeapTypeObject* et = (PyHeapTypeObject*)type;
if (et->ht_cached_keys == NULL) {
et->ht_cached_keys = _PyDict_NewKeysForClass(expected_number_of_shared_keys(type));
et->ht_cached_keys = _PyDict_NewKeysForClass();
if (et->ht_cached_keys == NULL) {
PyErr_NoMemory();
return -1;
Expand Down

0 comments on commit 010c64f

Please sign in to comment.