fix: use runtime.map_insert to not overallocate

This commit is contained in:
Rickard Andersson
2023-10-02 11:59:37 +03:00
parent 0a8b266c71
commit 55a1ba710b
+4 -6
View File
@@ -3,6 +3,7 @@ package json
import "core:mem"
import "core:unicode/utf8"
import "core:unicode/utf16"
import "core:runtime"
import "core:strconv"
Parser :: struct {
@@ -263,13 +264,10 @@ parse_object_body :: proc(p: ^Parser, end_token: Token_Kind) -> (obj: Object, er
return
}
if len(obj) == cap(obj) {
reserve_error := reserve(&obj, max(1, cap(obj) * 2))
if reserve_error != nil {
return nil, .Out_Of_Memory
}
insert_success := runtime.map_insert(&obj, key, elem)
if insert_success == nil {
return nil, .Out_Of_Memory
}
obj[key] = elem
if parse_comma(p) {
break