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

Commit89328f7

Browse files
authored
GH-115775: Use__static_attributes__ to initialize shared keys (GH-118468)
1 parentfe85a82 commit89328f7

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

‎Include/internal/pycore_dict.h

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

86-
externPyDictKeysObject*_PyDict_NewKeysForClass(void);
86+
externPyDictKeysObject*_PyDict_NewKeysForClass(PyHeapTypeObject*);
8787
externPyObject*_PyDict_FromKeys(PyObject*,PyObject*,PyObject*);
8888

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

‎Objects/dictobject.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6559,9 +6559,10 @@ dictvalues_reversed(PyObject *self, PyObject *Py_UNUSED(ignored))
65596559
/* Returns NULL if cannot allocate a new PyDictKeysObject,
65606560
but does not set an error */
65616561
PyDictKeysObject*
6562-
_PyDict_NewKeysForClass(void)
6562+
_PyDict_NewKeysForClass(PyHeapTypeObject*cls)
65636563
{
65646564
PyInterpreterState*interp=_PyInterpreterState_GET();
6565+
65656566
PyDictKeysObject*keys=new_keys_object(
65666567
interp,NEXT_LOG2_SHARED_KEYS_MAX_SIZE,1);
65676568
if (keys==NULL) {
@@ -6573,6 +6574,20 @@ _PyDict_NewKeysForClass(void)
65736574
keys->dk_usable=SHARED_KEYS_MAX_SIZE;
65746575
keys->dk_kind=DICT_KEYS_SPLIT;
65756576
}
6577+
if (cls->ht_type.tp_dict) {
6578+
PyObject*attrs=PyDict_GetItem(cls->ht_type.tp_dict,&_Py_ID(__static_attributes__));
6579+
if (attrs!=NULL&&PyTuple_Check(attrs)) {
6580+
for (Py_ssize_ti=0;i<PyTuple_GET_SIZE(attrs);i++) {
6581+
PyObject*key=PyTuple_GET_ITEM(attrs,i);
6582+
Py_hash_thash;
6583+
if (PyUnicode_CheckExact(key)&& (hash=unicode_get_hash(key))!=-1) {
6584+
if (insert_split_key(keys,key,hash)==DKIX_EMPTY) {
6585+
break;
6586+
}
6587+
}
6588+
}
6589+
}
6590+
}
65766591
returnkeys;
65776592
}
65786593

‎Objects/typeobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8334,7 +8334,7 @@ type_ready_managed_dict(PyTypeObject *type)
83348334
}
83358335
PyHeapTypeObject*et= (PyHeapTypeObject*)type;
83368336
if (et->ht_cached_keys==NULL) {
8337-
et->ht_cached_keys=_PyDict_NewKeysForClass();
8337+
et->ht_cached_keys=_PyDict_NewKeysForClass(et);
83388338
if (et->ht_cached_keys==NULL) {
83398339
PyErr_NoMemory();
83408340
return-1;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp