From d8f06ed55741fe52ec7bf260dddc1a369cfa05a7 Mon Sep 17 00:00:00 2001 From: Karl Zylinski Date: Wed, 1 Nov 2023 00:37:27 +0100 Subject: Reversed order of sort_maps_by_key check in marshal.odin to make PR comparison clearer. --- core/encoding/json/marshal.odin | 52 ++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'core/encoding') diff --git a/core/encoding/json/marshal.odin b/core/encoding/json/marshal.odin index e53ab9a7c..80b2e4dd4 100644 --- a/core/encoding/json/marshal.odin +++ b/core/encoding/json/marshal.odin @@ -275,27 +275,23 @@ marshal_to_writer :: proc(w: io.Writer, v: any, opt: ^Marshal_Options) -> (err: map_cap := uintptr(runtime.map_cap(m^)) ks, vs, hs, _, _ := runtime.map_kvh_data_dynamic(m^, info.map_info) - if opt.sort_maps_by_key { - Entry :: struct { - key: string, - value: any, - } - - // If we are sorting the map by key, then we temp alloc an array - // and sort it, then output the result. - sorted := make([dynamic]Entry, 0, map_cap, context.temp_allocator) + if !opt.sort_maps_by_key { + i := 0 for bucket_index in 0.. (err: case string: name = s case cstring: name = string(s) } + opt_write_key(w, opt, name) or_return case: return .Unsupported_Type } } - append(&sorted, Entry { key = name, value = any{value, info.value.id}}) - } - - slice.sort_by(sorted[:], proc(i, j: Entry) -> bool { return i.key < j.key }) - - for s, i in sorted { - opt_write_iteration(w, opt, i) or_return - opt_write_key(w, opt, s.key) or_return - marshal_to_writer(w, s.value, opt) or_return + marshal_to_writer(w, any{value, info.value.id}, opt) or_return } } else { - i := 0 + Entry :: struct { + key: string, + value: any, + } + + // If we are sorting the map by key, then we temp alloc an array + // and sort it, then output the result. + sorted := make([dynamic]Entry, 0, map_cap, context.temp_allocator) for bucket_index in 0.. (err: case string: name = s case cstring: name = string(s) } - opt_write_key(w, opt, name) or_return case: return .Unsupported_Type } } - marshal_to_writer(w, any{value, info.value.id}, opt) or_return + append(&sorted, Entry { key = name, value = any{value, info.value.id}}) + } + + slice.sort_by(sorted[:], proc(i, j: Entry) -> bool { return i.key < j.key }) + + for s, i in sorted { + opt_write_iteration(w, opt, i) or_return + opt_write_key(w, opt, s.key) or_return + marshal_to_writer(w, s.value, opt) or_return } } } -- cgit v1.2.3