mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-22 23:47:51 +00:00
Reduce the size of runtime.Type_Info
This commit is contained in:
@@ -506,7 +506,7 @@ _marshal_into_encoder :: proc(e: Encoder, v: any, ti: ^runtime.Type_Info) -> (er
|
||||
}
|
||||
|
||||
n: u64; {
|
||||
for _, i in info.names {
|
||||
for _, i in info.names[:info.field_count] {
|
||||
if field_name(info, i) != "-" {
|
||||
n += 1
|
||||
}
|
||||
@@ -522,7 +522,7 @@ _marshal_into_encoder :: proc(e: Encoder, v: any, ti: ^runtime.Type_Info) -> (er
|
||||
entries := make([dynamic]Name, 0, n, e.temp_allocator) or_return
|
||||
defer delete(entries)
|
||||
|
||||
for _, i in info.names {
|
||||
for _, i in info.names[:info.field_count] {
|
||||
fname := field_name(info, i)
|
||||
if fname == "-" {
|
||||
continue
|
||||
@@ -540,7 +540,7 @@ _marshal_into_encoder :: proc(e: Encoder, v: any, ti: ^runtime.Type_Info) -> (er
|
||||
marshal_entry(e, info, v, entry.name, entry.field) or_return
|
||||
}
|
||||
} else {
|
||||
for _, i in info.names {
|
||||
for _, i in info.names[:info.field_count] {
|
||||
fname := field_name(info, i)
|
||||
if fname == "-" {
|
||||
continue
|
||||
|
||||
@@ -618,7 +618,7 @@ _unmarshal_map :: proc(d: Decoder, v: any, ti: ^reflect.Type_Info, hdr: Header,
|
||||
|
||||
#partial switch t in ti.variant {
|
||||
case reflect.Type_Info_Struct:
|
||||
if t.is_raw_union {
|
||||
if .raw_union in t.flags {
|
||||
return _unsupported(v, hdr)
|
||||
}
|
||||
|
||||
|
||||
@@ -406,7 +406,7 @@ marshal_to_writer :: proc(w: io.Writer, v: any, opt: ^Marshal_Options) -> (err:
|
||||
ti := runtime.type_info_base(type_info_of(v.id))
|
||||
info := ti.variant.(runtime.Type_Info_Struct)
|
||||
first_iteration := true
|
||||
for name, i in info.names {
|
||||
for name, i in info.names[:info.field_count] {
|
||||
omitempty := false
|
||||
|
||||
json_name, extra := json_name_from_tag_value(reflect.struct_tag_get(reflect.Struct_Tag(info.tags[i]), "json"))
|
||||
|
||||
@@ -368,7 +368,7 @@ unmarshal_object :: proc(p: ^Parser, v: any, end_token: Token_Kind) -> (err: Unm
|
||||
|
||||
#partial switch t in ti.variant {
|
||||
case reflect.Type_Info_Struct:
|
||||
if t.is_raw_union {
|
||||
if .raw_union in t.flags {
|
||||
return UNSUPPORTED_TYPE
|
||||
}
|
||||
|
||||
|
||||
+8
-8
@@ -1861,7 +1861,7 @@ handle_tag :: proc(state: ^Info_State, data: rawptr, info: reflect.Type_Info_Str
|
||||
if optional_len == nil {
|
||||
return
|
||||
}
|
||||
for f, i in info.names {
|
||||
for f, i in info.names[:info.field_count] {
|
||||
if f != field_name {
|
||||
continue
|
||||
}
|
||||
@@ -1965,7 +1965,7 @@ fmt_struct :: proc(fi: ^Info, v: any, the_verb: rune, info: runtime.Type_Info_St
|
||||
fmt_bad_verb(fi, the_verb)
|
||||
return
|
||||
}
|
||||
if info.is_raw_union {
|
||||
if .raw_union in info.flags {
|
||||
if type_name == "" {
|
||||
io.write_string(fi.writer, "(raw union)", &fi.n)
|
||||
} else {
|
||||
@@ -1989,7 +1989,7 @@ fmt_struct :: proc(fi: ^Info, v: any, the_verb: rune, info: runtime.Type_Info_St
|
||||
// fi.hash = false;
|
||||
fi.indent += 1
|
||||
|
||||
is_empty := len(info.names) == 0
|
||||
is_empty := info.field_count == 0
|
||||
|
||||
if !is_soa && hash && !is_empty {
|
||||
io.write_byte(fi.writer, '\n', &fi.n)
|
||||
@@ -2010,17 +2010,17 @@ fmt_struct :: proc(fi: ^Info, v: any, the_verb: rune, info: runtime.Type_Info_St
|
||||
base_type_name = v.name
|
||||
}
|
||||
|
||||
actual_field_count := len(info.names)
|
||||
actual_field_count := info.field_count
|
||||
|
||||
n := uintptr(info.soa_len)
|
||||
|
||||
if info.soa_kind == .Slice {
|
||||
actual_field_count = len(info.names)-1 // len
|
||||
actual_field_count = info.field_count-1 // len
|
||||
|
||||
n = uintptr((^int)(uintptr(v.data) + info.offsets[actual_field_count])^)
|
||||
|
||||
} else if info.soa_kind == .Dynamic {
|
||||
actual_field_count = len(info.names)-3 // len, cap, allocator
|
||||
actual_field_count = info.field_count-3 // len, cap, allocator
|
||||
|
||||
n = uintptr((^int)(uintptr(v.data) + info.offsets[actual_field_count])^)
|
||||
}
|
||||
@@ -2099,7 +2099,7 @@ fmt_struct :: proc(fi: ^Info, v: any, the_verb: rune, info: runtime.Type_Info_St
|
||||
}
|
||||
} else {
|
||||
field_count := -1
|
||||
for name, i in info.names {
|
||||
for name, i in info.names[:info.field_count] {
|
||||
optional_len: int = -1
|
||||
use_nul_termination: bool = false
|
||||
verb := the_verb if the_verb == 'w' else 'v'
|
||||
@@ -2605,7 +2605,7 @@ fmt_bit_field :: proc(fi: ^Info, v: any, verb: rune, info: runtime.Type_Info_Bit
|
||||
|
||||
|
||||
field_count := -1
|
||||
for name, i in info.names {
|
||||
for name, i in info.names[:info.field_count] {
|
||||
field_verb := verb
|
||||
if handle_bit_field_tag(v.data, info, i, &field_verb) {
|
||||
continue
|
||||
|
||||
+13
-13
@@ -391,7 +391,7 @@ Struct_Field :: struct {
|
||||
struct_field_at :: proc(T: typeid, i: int) -> (field: Struct_Field) {
|
||||
ti := runtime.type_info_base(type_info_of(T))
|
||||
if s, ok := ti.variant.(runtime.Type_Info_Struct); ok {
|
||||
if 0 <= i && i < len(s.names) {
|
||||
if 0 <= i && i < int(s.field_count) {
|
||||
field.name = s.names[i]
|
||||
field.type = s.types[i]
|
||||
field.tag = Struct_Tag(s.tags[i])
|
||||
@@ -406,7 +406,7 @@ struct_field_at :: proc(T: typeid, i: int) -> (field: Struct_Field) {
|
||||
struct_field_by_name :: proc(T: typeid, name: string) -> (field: Struct_Field) {
|
||||
ti := runtime.type_info_base(type_info_of(T))
|
||||
if s, ok := ti.variant.(runtime.Type_Info_Struct); ok {
|
||||
for fname, i in s.names {
|
||||
for fname, i in s.names[:s.field_count] {
|
||||
if fname == name {
|
||||
field.name = s.names[i]
|
||||
field.type = s.types[i]
|
||||
@@ -427,7 +427,7 @@ struct_field_value_by_name :: proc(a: any, field: string, allow_using := false)
|
||||
ti := runtime.type_info_base(type_info_of(a.id))
|
||||
|
||||
if s, ok := ti.variant.(runtime.Type_Info_Struct); ok {
|
||||
for name, i in s.names {
|
||||
for name, i in s.names[:s.field_count] {
|
||||
if name == field {
|
||||
return any{
|
||||
rawptr(uintptr(a.data) + s.offsets[i]),
|
||||
@@ -463,7 +463,7 @@ struct_field_value :: proc(a: any, field: Struct_Field) -> any {
|
||||
struct_field_names :: proc(T: typeid) -> []string {
|
||||
ti := runtime.type_info_base(type_info_of(T))
|
||||
if s, ok := ti.variant.(runtime.Type_Info_Struct); ok {
|
||||
return s.names
|
||||
return s.names[:s.field_count]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -472,7 +472,7 @@ struct_field_names :: proc(T: typeid) -> []string {
|
||||
struct_field_types :: proc(T: typeid) -> []^Type_Info {
|
||||
ti := runtime.type_info_base(type_info_of(T))
|
||||
if s, ok := ti.variant.(runtime.Type_Info_Struct); ok {
|
||||
return s.types
|
||||
return s.types[:s.field_count]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -482,7 +482,7 @@ struct_field_types :: proc(T: typeid) -> []^Type_Info {
|
||||
struct_field_tags :: proc(T: typeid) -> []Struct_Tag {
|
||||
ti := runtime.type_info_base(type_info_of(T))
|
||||
if s, ok := ti.variant.(runtime.Type_Info_Struct); ok {
|
||||
return transmute([]Struct_Tag)s.tags
|
||||
return transmute([]Struct_Tag)s.tags[:s.field_count]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -491,7 +491,7 @@ struct_field_tags :: proc(T: typeid) -> []Struct_Tag {
|
||||
struct_field_offsets :: proc(T: typeid) -> []uintptr {
|
||||
ti := runtime.type_info_base(type_info_of(T))
|
||||
if s, ok := ti.variant.(runtime.Type_Info_Struct); ok {
|
||||
return s.offsets
|
||||
return s.offsets[:s.field_count]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -501,11 +501,11 @@ struct_fields_zipped :: proc(T: typeid) -> (fields: #soa[]Struct_Field) {
|
||||
ti := runtime.type_info_base(type_info_of(T))
|
||||
if s, ok := ti.variant.(runtime.Type_Info_Struct); ok {
|
||||
return soa_zip(
|
||||
name = s.names,
|
||||
type = s.types,
|
||||
tag = transmute([]Struct_Tag)s.tags,
|
||||
offset = s.offsets,
|
||||
is_using = s.usings,
|
||||
name = s.names[:s.field_count],
|
||||
type = s.types[:s.field_count],
|
||||
tag = ([^]Struct_Tag)(s.tags)[:s.field_count],
|
||||
offset = s.offsets[:s.field_count],
|
||||
is_using = s.usings[:s.field_count],
|
||||
)
|
||||
}
|
||||
return nil
|
||||
@@ -1569,7 +1569,7 @@ equal :: proc(a, b: any, including_indirect_array_recursion := false, recursion_
|
||||
if v.equal != nil {
|
||||
return v.equal(a.data, b.data)
|
||||
} else {
|
||||
for offset, i in v.offsets {
|
||||
for offset, i in v.offsets[:v.field_count] {
|
||||
x := rawptr(uintptr(a.data) + offset)
|
||||
y := rawptr(uintptr(b.data) + offset)
|
||||
id := v.types[i].id
|
||||
|
||||
+13
-14
@@ -115,16 +115,14 @@ are_types_identical :: proc(a, b: ^Type_Info) -> bool {
|
||||
case Type_Info_Struct:
|
||||
y := b.variant.(Type_Info_Struct) or_return
|
||||
switch {
|
||||
case len(x.types) != len(y.types),
|
||||
x.is_packed != y.is_packed,
|
||||
x.is_raw_union != y.is_raw_union,
|
||||
x.custom_align != y.custom_align,
|
||||
case x.field_count != y.field_count,
|
||||
x.flags != y.flags,
|
||||
x.soa_kind != y.soa_kind,
|
||||
x.soa_base_type != y.soa_base_type,
|
||||
x.soa_len != y.soa_len:
|
||||
return false
|
||||
}
|
||||
for _, i in x.types {
|
||||
for i in 0..<x.field_count {
|
||||
xn, yn := x.names[i], y.names[i]
|
||||
xt, yt := x.types[i], y.types[i]
|
||||
xl, yl := x.tags[i], y.tags[i]
|
||||
@@ -179,8 +177,8 @@ are_types_identical :: proc(a, b: ^Type_Info) -> bool {
|
||||
case Type_Info_Bit_Field:
|
||||
y := b.variant.(Type_Info_Bit_Field) or_return
|
||||
if !are_types_identical(x.backing_type, y.backing_type) { return false }
|
||||
if len(x.names) != len(y.names) { return false }
|
||||
for _, i in x.names {
|
||||
if x.field_count != y.field_count { return false }
|
||||
for _, i in x.names[:x.field_count] {
|
||||
if x.names[i] != y.names[i] {
|
||||
return false
|
||||
}
|
||||
@@ -368,13 +366,13 @@ is_tuple :: proc(info: ^Type_Info) -> bool {
|
||||
is_struct :: proc(info: ^Type_Info) -> bool {
|
||||
if info == nil { return false }
|
||||
s, ok := type_info_base(info).variant.(Type_Info_Struct)
|
||||
return ok && !s.is_raw_union
|
||||
return ok && .raw_union not_in s.flags
|
||||
}
|
||||
@(require_results)
|
||||
is_raw_union :: proc(info: ^Type_Info) -> bool {
|
||||
if info == nil { return false }
|
||||
s, ok := type_info_base(info).variant.(Type_Info_Struct)
|
||||
return ok && s.is_raw_union
|
||||
return ok && .raw_union in s.flags
|
||||
}
|
||||
@(require_results)
|
||||
is_union :: proc(info: ^Type_Info) -> bool {
|
||||
@@ -656,15 +654,16 @@ write_type_writer :: proc(w: io.Writer, ti: ^Type_Info, n_written: ^int = nil) -
|
||||
}
|
||||
|
||||
io.write_string(w, "struct ", &n) or_return
|
||||
if info.is_packed { io.write_string(w, "#packed ", &n) or_return }
|
||||
if info.is_raw_union { io.write_string(w, "#raw_union ", &n) or_return }
|
||||
if info.custom_align {
|
||||
if .packed in info.flags { io.write_string(w, "#packed ", &n) or_return }
|
||||
if .raw_union in info.flags { io.write_string(w, "#raw_union ", &n) or_return }
|
||||
if .no_copy in info.flags { io.write_string(w, "#no_copy ", &n) or_return }
|
||||
if .align in info.flags {
|
||||
io.write_string(w, "#align(", &n) or_return
|
||||
io.write_i64(w, i64(ti.align), 10, &n) or_return
|
||||
io.write_string(w, ") ", &n) or_return
|
||||
}
|
||||
io.write_byte(w, '{', &n) or_return
|
||||
for name, i in info.names {
|
||||
for name, i in info.names[:info.field_count] {
|
||||
if i > 0 { io.write_string(w, ", ", &n) or_return }
|
||||
io.write_string(w, name, &n) or_return
|
||||
io.write_string(w, ": ", &n) or_return
|
||||
@@ -722,7 +721,7 @@ write_type_writer :: proc(w: io.Writer, ti: ^Type_Info, n_written: ^int = nil) -
|
||||
io.write_string(w, "bit_field ", &n) or_return
|
||||
write_type(w, info.backing_type, &n) or_return
|
||||
io.write_string(w, " {", &n) or_return
|
||||
for name, i in info.names {
|
||||
for name, i in info.names[:info.field_count] {
|
||||
if i > 0 { io.write_string(w, ", ", &n) or_return }
|
||||
io.write_string(w, name, &n) or_return
|
||||
io.write_string(w, ": ", &n) or_return
|
||||
|
||||
Reference in New Issue
Block a user