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

Appearance settings

Commit 1266799

Browse filesBrowse files
committed
Accessing a single element should optimistically avoid locking for performance
1 parent 92abb01 commit 1266799
Copy full SHA for 1266799

File tree

2 files changed

+499
-100
lines changed
Filter options

2 files changed

+499
-100
lines changed

‎Include/internal/pycore_dict.h

Copy file name to clipboardExpand all lines: Include/internal/pycore_dict.h
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ static inline PyDictUnicodeEntry* DK_UNICODE_ENTRIES(PyDictKeysObject *dk) {
210210
#define DICT_VERSION_INCREMENT (1 << (DICT_MAX_WATCHERS + DICT_WATCHED_MUTATION_BITS))
211211
#define DICT_WATCHER_MASK ((1 << DICT_MAX_WATCHERS) - 1)
212212

213+
#define DICT_VALUES_SIZE(values) ((uint8_t *)values)[-1]
214+
213215
#ifdef Py_GIL_DISABLED
214216
#define DICT_NEXT_VERSION(INTERP) \
215217
(_Py_atomic_add_uint64(&(INTERP)->dict_state.global_version, DICT_VERSION_INCREMENT) + DICT_VERSION_INCREMENT)
@@ -255,7 +257,7 @@ _PyDictValues_AddToInsertionOrder(PyDictValues *values, Py_ssize_t ix)
255257
assert(ix < SHARED_KEYS_MAX_SIZE);
256258
uint8_t *size_ptr = ((uint8_t *)values)-2;
257259
int size = *size_ptr;
258-
assert(size+2 < ((uint8_t *)values)[-1]);
260+
assert(size+2 < DICT_VALUES_SIZE(values));
259261
size++;
260262
size_ptr[-size] = (uint8_t)ix;
261263
*size_ptr = size;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.