-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Retain order of keys in dict when deleting a key #2550
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 all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -557,10 +557,13 @@ impl<T: Clone> Dict<T> { | |
| let removed = if entry_index == inner.used { | ||
| inner.entries.pop().unwrap() | ||
| } else { | ||
| let last_index = inner.entries.last().unwrap().index; | ||
| let removed = inner.entries.swap_remove(entry_index); | ||
| inner.indices[last_index] = entry_index as i64; | ||
| removed | ||
| let entries_rem = entry_index + 1; | ||
| let entries_len = inner.entries.len(); | ||
| for move_entry_idx in entries_rem..entries_len { | ||
| let index_index = inner.entries[move_entry_idx].index; | ||
| inner.indices[index_index] = move_entry_idx as i64 - 1; | ||
| } | ||
|
Comment on lines
+562
to
+565
Member
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 don't think CPython uses loop for this. What happens if the dict has very many items? Would you check
Member
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. Yeah, this definitely won't be a loop, pretty sure that leads to
Member
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. @eldpswp99 is working on this again |
||
| inner.entries.remove(entry_index) | ||
| }; | ||
| Ok(Some(removed)) | ||
| } | ||
|
|
||
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.
oh... I believed it is not swap_remove and we were doing it as how CPython does.