mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Merge pull request #4273 from discord9/fix_dict
Allow retry if `as_mut` fail when insert Dict
This commit is contained in:
@@ -248,9 +248,13 @@ impl<T: Clone> Dict<T> {
|
||||
if let Some(index) = entry_index.index() {
|
||||
// Update existing key
|
||||
if let Some(entry) = inner.entries.get_mut(index) {
|
||||
let entry = entry
|
||||
.as_mut()
|
||||
.expect("The dict was changed since we did lookup.");
|
||||
let Some(entry) = entry.as_mut() else {
|
||||
// The dict was changed since we did lookup. Let's try again.
|
||||
// this is very rare to happen
|
||||
// (and seems only happen with very high freq gc, and about one time in 10000 iters)
|
||||
// but still possible
|
||||
continue;
|
||||
};
|
||||
if entry.index == index_index {
|
||||
let removed = std::mem::replace(&mut entry.value, value);
|
||||
// defer dec RC
|
||||
|
||||
Reference in New Issue
Block a user