Merge pull request #4273 from discord9/fix_dict

Allow retry if `as_mut` fail when insert Dict
This commit is contained in:
Jim Fasarakis-Hilliard
2022-11-13 09:57:19 +02:00
committed by GitHub

View File

@@ -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