mirror of
https://github.com/typst/typst
synced 2025-06-30 09:12:52 +08:00
Fix removal order for dictionary
Switches to `shift_remove` for now. In the future, we should look into a more efficient implementation. Fixes #1258.
This commit is contained in:
parent
08870d4a4c
commit
3d83960322
@ -88,7 +88,7 @@ impl Dict {
|
|||||||
|
|
||||||
/// Remove a mapping by `key` and return the value.
|
/// Remove a mapping by `key` and return the value.
|
||||||
pub fn remove(&mut self, key: &str) -> StrResult<Value> {
|
pub fn remove(&mut self, key: &str) -> StrResult<Value> {
|
||||||
match Arc::make_mut(&mut self.0).remove(key) {
|
match Arc::make_mut(&mut self.0).shift_remove(key) {
|
||||||
Some(value) => Ok(value),
|
Some(value) => Ok(value),
|
||||||
None => Err(missing_key(key)),
|
None => Err(missing_key(key)),
|
||||||
}
|
}
|
||||||
|
@ -60,6 +60,12 @@
|
|||||||
#test("c" in dict, false)
|
#test("c" in dict, false)
|
||||||
#test(dict, (a: 3, b: 1))
|
#test(dict, (a: 3, b: 1))
|
||||||
|
|
||||||
|
---
|
||||||
|
// Test that removal keeps order.
|
||||||
|
#let dict = (a: 1, b: 2, c: 3, d: 4)
|
||||||
|
#dict.remove("b")
|
||||||
|
#test(dict.keys(), ("a", "c", "d"))
|
||||||
|
|
||||||
---
|
---
|
||||||
// Error: 24-29 duplicate key: first
|
// Error: 24-29 duplicate key: first
|
||||||
#(first: 1, second: 2, first: 3)
|
#(first: 1, second: 2, first: 3)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user