Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdedffa7

Browse files
committed
Use __static_attributes__ to initialize shared keys
1 parent21c09d9 commitdedffa7

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

‎Include/internal/pycore_dict.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ typedef struct {
8181
PyObject*me_value;/* This field is only meaningful for combined tables */
8282
}PyDictUnicodeEntry;
8383

84-
externPyDictKeysObject*_PyDict_NewKeysForClass(void);
84+
externPyDictKeysObject*_PyDict_NewKeysForClass(PyHeapTypeObject*);
8585
externPyObject*_PyDict_FromKeys(PyObject*,PyObject*,PyObject*);
8686

8787
/* Gets a version number unique to the current state of the keys of dict, if possible.

‎Objects/dictobject.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6586,9 +6586,10 @@ dictvalues_reversed(PyObject *self, PyObject *Py_UNUSED(ignored))
65866586
/* Returns NULL if cannot allocate a new PyDictKeysObject,
65876587
but does not set an error */
65886588
PyDictKeysObject*
6589-
_PyDict_NewKeysForClass(void)
6589+
_PyDict_NewKeysForClass(PyHeapTypeObject*cls)
65906590
{
65916591
PyInterpreterState*interp=_PyInterpreterState_GET();
6592+
65926593
PyDictKeysObject*keys=new_keys_object(
65936594
interp,NEXT_LOG2_SHARED_KEYS_MAX_SIZE,1);
65946595
if (keys==NULL) {
@@ -6600,6 +6601,18 @@ _PyDict_NewKeysForClass(void)
66006601
keys->dk_usable=SHARED_KEYS_MAX_SIZE;
66016602
keys->dk_kind=DICT_KEYS_SPLIT;
66026603
}
6604+
if (cls->ht_type.tp_dict) {
6605+
PyObject*attrs=PyDict_GetItem(cls->ht_type.tp_dict,&_Py_ID(__static_attributes__));
6606+
if (attrs!=NULL&&PyTuple_Check(attrs)) {
6607+
for (Py_ssize_ti;i<PyTuple_GET_SIZE(attrs);i++) {
6608+
PyObject*key=PyTuple_GET_ITEM(attrs,i);
6609+
Py_hash_thash;
6610+
if (PyUnicode_CheckExact(key)&& (hash=unicode_get_hash(key))!=-1) {
6611+
insert_split_key(keys,key,hash);
6612+
}
6613+
}
6614+
}
6615+
}
66036616
returnkeys;
66046617
}
66056618

‎Objects/typeobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7883,7 +7883,7 @@ type_ready_managed_dict(PyTypeObject *type)
78837883
}
78847884
PyHeapTypeObject*et= (PyHeapTypeObject*)type;
78857885
if (et->ht_cached_keys==NULL) {
7886-
et->ht_cached_keys=_PyDict_NewKeysForClass();
7886+
et->ht_cached_keys=_PyDict_NewKeysForClass(et);
78877887
if (et->ht_cached_keys==NULL) {
78887888
PyErr_NoMemory();
78897889
return-1;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp