diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2025-11-27 09:06:30 +0000 |
|---|---|---|
| committer | gingerBill <gingerBill@users.noreply.github.com> | 2025-11-27 09:06:30 +0000 |
| commit | 5380cf8b90132e5a1a638d9e90d0e3b6b1ed0d64 (patch) | |
| tree | 03a75bbe248aceee5f8999ddea382c82ed37a037 /core | |
| parent | adcbfb7861f23ad459b7652adc3c38c4c639ec8e (diff) | |
`core:fmt` lvalues in `for` loops to minimize stack usage
Diffstat (limited to 'core')
| -rw-r--r-- | core/fmt/fmt.odin | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/core/fmt/fmt.odin b/core/fmt/fmt.odin index 9c245de94..dec4e90fa 100644 --- a/core/fmt/fmt.odin +++ b/core/fmt/fmt.odin @@ -693,7 +693,7 @@ wprintf :: proc(w: io.Writer, fmt: string, args: ..any, flush := true, newline : fi: Info end := len(fmt) unused_args: bit_set[0 ..< MAX_CHECKED_ARGS] - for i in 0 ..< len(args) { + for _, i in args { unused_args += {i} } @@ -816,7 +816,7 @@ wprintf :: proc(w: io.Writer, fmt: string, args: ..any, flush := true, newline : } } - if unused_args != {} { + if unused_args != nil { // Use default options when formatting extra arguments. extra_fi := Info { writer = fi.writer, n = fi.n } @@ -1281,7 +1281,7 @@ _fmt_memory :: proc(fi: ^Info, u: u64, is_signed: bool, bit_size: int, units: st if !fi.plus { // Strip sign from "+<value>" but not "+Inf". if str[0] == '+' && str[1] != 'I' { - str = str[1:] + str = str[1:] } } @@ -1711,7 +1711,7 @@ fmt_enum :: proc(fi: ^Info, v: any, verb: rune) { } type_info := type_info_of(v.id) - #partial switch e in type_info.variant { + #partial switch &e in type_info.variant { case: fmt_bad_verb(fi, verb) case runtime.Type_Info_Enum: switch verb { @@ -1751,7 +1751,7 @@ stored_enum_value_to_string :: proc(enum_type: ^runtime.Type_Info, ev: runtime.T et := runtime.type_info_base(enum_type) ev := ev ev += runtime.Type_Info_Enum_Value(offset) - #partial switch e in et.variant { + #partial switch &e in et.variant { case: return "", false case runtime.Type_Info_Enum: if reflect.is_string(e.base) { @@ -1788,7 +1788,7 @@ fmt_bit_set :: proc(fi: ^Info, v: any, name: string = "", verb: rune = 'v') { return false } t := runtime.type_info_base(ti) - #partial switch info in t.variant { + #partial switch &info in t.variant { case runtime.Type_Info_Integer: switch info.endianness { case .Platform: return false @@ -1802,7 +1802,7 @@ fmt_bit_set :: proc(fi: ^Info, v: any, name: string = "", verb: rune = 'v') { byte_swap :: bits.byte_swap type_info := type_info_of(v.id) - #partial switch info in type_info.variant { + #partial switch &info in type_info.variant { case runtime.Type_Info_Named: val := v val.id = info.base.id @@ -1937,7 +1937,7 @@ fmt_write_array :: proc(fi: ^Info, array_data: rawptr, count: int, elem_size: in } fi.record_level += 1 defer fi.record_level -= 1 - + if fi.hash { io.write_byte(fi.writer, '\n', &fi.n) defer fmt_write_indent(fi) @@ -2528,7 +2528,7 @@ fmt_named :: proc(fi: ^Info, v: any, verb: rune, info: runtime.Type_Info_Named) } } - #partial switch b in info.base.variant { + #partial switch &b in info.base.variant { case runtime.Type_Info_Struct: fmt_struct(fi, v, verb, b, info.name) case runtime.Type_Info_Bit_Field: @@ -2794,7 +2794,7 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) { fi.ignore_user_formatters = false type_info := type_info_of(v.id) - switch info in type_info.variant { + switch &info in type_info.variant { case runtime.Type_Info_Any: // Ignore case runtime.Type_Info_Parameters: // Ignore @@ -2819,7 +2819,7 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) { elem := runtime.type_info_base(info.elem) if elem != nil { - #partial switch e in elem.variant { + #partial switch &e in elem.variant { case runtime.Type_Info_Array, runtime.Type_Info_Slice, runtime.Type_Info_Dynamic_Array, @@ -2881,7 +2881,7 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) { return } - #partial switch e in elem.variant { + #partial switch &e in elem.variant { case runtime.Type_Info_Integer: switch verb { case 's', 'q': @@ -3238,7 +3238,7 @@ fmt_arg :: proc(fi: ^Info, arg: any, verb: rune) { base_arg := arg base_arg.id = runtime.typeid_base(base_arg.id) - switch a in base_arg { + switch &a in base_arg { case bool: fmt_bool(fi, a, verb) case b8: fmt_bool(fi, bool(a), verb) case b16: fmt_bool(fi, bool(a), verb) |