mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-02 04:38:16 +00:00
Use intrinsics.alloca rather than context.temp_allocator in json.unmarshal_object
This commit is contained in:
@@ -6,6 +6,7 @@ import "core:reflect"
|
|||||||
import "core:strconv"
|
import "core:strconv"
|
||||||
import "core:strings"
|
import "core:strings"
|
||||||
import "base:runtime"
|
import "base:runtime"
|
||||||
|
import "base:intrinsics"
|
||||||
|
|
||||||
Unmarshal_Data_Error :: enum {
|
Unmarshal_Data_Error :: enum {
|
||||||
Invalid_Data,
|
Invalid_Data,
|
||||||
@@ -368,11 +369,14 @@ unmarshal_object :: proc(p: ^Parser, v: any, end_token: Token_Kind) -> (err: Unm
|
|||||||
unmarshal_expect_token(p, .Colon)
|
unmarshal_expect_token(p, .Colon)
|
||||||
|
|
||||||
fields := reflect.struct_fields_zipped(ti.id)
|
fields := reflect.struct_fields_zipped(ti.id)
|
||||||
|
|
||||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD(ignore = context.temp_allocator == context.allocator)
|
|
||||||
|
|
||||||
field_used := make([]bool, len(fields), context.temp_allocator)
|
field_test :: #force_inline proc "contextless" (field_used: [^]byte, index: int) -> bool {
|
||||||
|
prev_set := field_used[index/8] & byte(index&7) != 0
|
||||||
|
field_used[index/8] |= byte(index&7)
|
||||||
|
return prev_set
|
||||||
|
}
|
||||||
|
|
||||||
|
field_used := intrinsics.alloca((len(fields)+7)/8, 1)
|
||||||
use_field_idx := -1
|
use_field_idx := -1
|
||||||
|
|
||||||
for field, field_idx in fields {
|
for field, field_idx in fields {
|
||||||
@@ -393,10 +397,9 @@ unmarshal_object :: proc(p: ^Parser, v: any, end_token: Token_Kind) -> (err: Unm
|
|||||||
}
|
}
|
||||||
|
|
||||||
if use_field_idx >= 0 {
|
if use_field_idx >= 0 {
|
||||||
if field_used[use_field_idx] {
|
if field_test(field_used, use_field_idx) {
|
||||||
return .Multiple_Use_Field
|
return .Multiple_Use_Field
|
||||||
}
|
}
|
||||||
field_used[use_field_idx] = true
|
|
||||||
offset := fields[use_field_idx].offset
|
offset := fields[use_field_idx].offset
|
||||||
type := fields[use_field_idx].type
|
type := fields[use_field_idx].type
|
||||||
name := fields[use_field_idx].name
|
name := fields[use_field_idx].name
|
||||||
|
|||||||
Reference in New Issue
Block a user