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.
This commit is contained in:
2023-11-06 20:15:02 -08:00
parent 73575a43a7
commit ed913ab3a3

View File

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