From ed913ab3a35ca45eee78052d7220a2278dcf1901 Mon Sep 17 00:00:00 2001 From: torque Date: Mon, 6 Nov 2023 20:15:02 -0800 Subject: [PATCH] state: properly update key order when preserving the last key Since I decided that Nice would guarantee (for some definition of guarantee) preserving the order of keys in a document, this has some impact on the parsing modes that tolerate duplicate keys. In the case that the last instance of a duplicate key is the one that is preserved, its order should be reflected. In general, however, it's recommended not to permit duplicate keys, which is why that's the default behavior. --- src/parser/state.zig | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/parser/state.zig b/src/parser/state.zig index 381cdc2..c1ed25b 100644 --- a/src/parser/state.zig +++ b/src/parser/state.zig @@ -802,7 +802,10 @@ pub const State = struct { return error.DuplicateKey; }, .use_first => {}, - .use_last => gop.value_ptr.* = value, + .use_last => { + _ = map.orderedRemove(key); + map.putAssumeCapacityNoClobber(key, value); + }, } else gop.value_ptr.* = value;