-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-115999: Specialize LOAD_ATTR
for instance and class receivers in free-threaded builds
#128164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 54 commits
8eeb4fe
fcd05a0
5c03db0
a576748
8475fd6
29c3356
4f9eeb3
e9050fc
ade57f2
0a87264
816e22f
ca1e232
945b61c
feb7d34
ecfd199
9fda5db
3b2c220
408e44b
16aab70
d0920ea
e7cea82
8dac8c4
d29b3aa
b0b8102
85dab0d
581869e
96be738
9afe052
e190a0d
8c78369
cdf8eb5
1398699
3fbe18b
5aa68cc
e1bf1f4
396edb1
e5e2508
fa02260
47c794f
3876bc7
08d14d0
56e9a8a
8ca405b
4c7a4b9
1b787b3
b868363
d6d4c73
9755562
9673f78
6c3041f
a20a4a4
35b31c6
e5a7ae9
bb00f5a
b6ae487
11a351d
6f8aebf
07b7c20
1870885
f1fdcc6
8b71951
7190a2e
8b96368
db02869
dc3ba7f
e07fb62
a3f89b7
3baa840
9250e4e
675eb82
d24dc3a
10d693d
7ab3ec6
8c70ea4
3616eab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1129,6 +1129,21 @@ dictkeys_generic_lookup(PyDictObject *mp, PyDictKeysObject* dk, PyObject *key, P | |
return do_lookup(mp, dk, key, hash, compare_generic); | ||
} | ||
|
||
static Py_hash_t | ||
check_keys_and_hash(PyDictKeysObject *dk, PyObject *key) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't tell from the name what this is checking. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is factoring out some common code into a helper. I'll split it into two helpers with more descriptive names. |
||
{ | ||
DictKeysKind kind = dk->dk_kind; | ||
if (!PyUnicode_CheckExact(key) || kind == DICT_KEYS_GENERAL) { | ||
return -1; | ||
} | ||
Py_hash_t hash = unicode_get_hash(key); | ||
if (hash == -1) { | ||
hash = PyUnicode_Type.tp_hash(key); | ||
assert(hash != -1); | ||
} | ||
return hash; | ||
} | ||
|
||
#ifdef Py_GIL_DISABLED | ||
static Py_ssize_t | ||
unicodekeys_lookup_unicode_threadsafe(PyDictKeysObject* dk, PyObject *key, | ||
|
@@ -1167,19 +1182,27 @@ unicodekeys_lookup_split(PyDictKeysObject* dk, PyObject *key, Py_hash_t hash) | |
Py_ssize_t | ||
_PyDictKeys_StringLookup(PyDictKeysObject* dk, PyObject *key) | ||
{ | ||
DictKeysKind kind = dk->dk_kind; | ||
if (!PyUnicode_CheckExact(key) || kind == DICT_KEYS_GENERAL) { | ||
Py_hash_t hash = check_keys_and_hash(dk, key); | ||
if (hash == -1) { | ||
return DKIX_ERROR; | ||
} | ||
Py_hash_t hash = unicode_get_hash(key); | ||
return unicodekeys_lookup_unicode(dk, key, hash); | ||
} | ||
|
||
Py_ssize_t | ||
_PyDictKeys_StringLookupAndVersion(PyDictKeysObject *dk, PyObject *key, uint32_t *version) | ||
{ | ||
Py_hash_t hash = check_keys_and_hash(dk, key); | ||
if (hash == -1) { | ||
hash = PyUnicode_Type.tp_hash(key); | ||
if (hash == -1) { | ||
PyErr_Clear(); | ||
return DKIX_ERROR; | ||
} | ||
return DKIX_ERROR; | ||
} | ||
return unicodekeys_lookup_unicode(dk, key, hash); | ||
|
||
Py_ssize_t ix; | ||
LOCK_KEYS(dk); | ||
ix = unicodekeys_lookup_unicode(dk, key, hash); | ||
*version = _PyDictKeys_GetVersionForCurrentState(_PyInterpreterState_GET(), dk); | ||
UNLOCK_KEYS(dk); | ||
return ix; | ||
} | ||
|
||
/* Like _PyDictKeys_StringLookup() but only works on split keys. Note | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks a bit mysterious to me. Does this do something different than what
class a: [...]
does? Calling it an instance (which techically true) is a bit confusing too. I would just say a "set to an object that uses ...". It's a class object. If you need it written like this, I think a little helper function with a docstring explaining why it must be done that way would help:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see later there is
item.a = type("Foo", (object,), {})
so you want an expression not a statement.