Skip to content

Commit 5380cf8

Browse files
committed
core:fmt lvalues in for loops to minimize stack usage
1 parent adcbfb7 commit 5380cf8

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

core/fmt/fmt.odin

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ wprintf :: proc(w: io.Writer, fmt: string, args: ..any, flush := true, newline :
693693
fi: Info
694694
end := len(fmt)
695695
unused_args: bit_set[0 ..< MAX_CHECKED_ARGS]
696-
for i in 0 ..< len(args) {
696+
for _, i in args {
697697
unused_args += {i}
698698
}
699699

@@ -816,7 +816,7 @@ wprintf :: proc(w: io.Writer, fmt: string, args: ..any, flush := true, newline :
816816
}
817817
}
818818

819-
if unused_args != {} {
819+
if unused_args != nil {
820820
// Use default options when formatting extra arguments.
821821
extra_fi := Info { writer = fi.writer, n = fi.n }
822822

@@ -1281,7 +1281,7 @@ _fmt_memory :: proc(fi: ^Info, u: u64, is_signed: bool, bit_size: int, units: st
12811281
if !fi.plus {
12821282
// Strip sign from "+<value>" but not "+Inf".
12831283
if str[0] == '+' && str[1] != 'I' {
1284-
str = str[1:]
1284+
str = str[1:]
12851285
}
12861286
}
12871287

@@ -1711,7 +1711,7 @@ fmt_enum :: proc(fi: ^Info, v: any, verb: rune) {
17111711
}
17121712

17131713
type_info := type_info_of(v.id)
1714-
#partial switch e in type_info.variant {
1714+
#partial switch &e in type_info.variant {
17151715
case: fmt_bad_verb(fi, verb)
17161716
case runtime.Type_Info_Enum:
17171717
switch verb {
@@ -1751,7 +1751,7 @@ stored_enum_value_to_string :: proc(enum_type: ^runtime.Type_Info, ev: runtime.T
17511751
et := runtime.type_info_base(enum_type)
17521752
ev := ev
17531753
ev += runtime.Type_Info_Enum_Value(offset)
1754-
#partial switch e in et.variant {
1754+
#partial switch &e in et.variant {
17551755
case: return "", false
17561756
case runtime.Type_Info_Enum:
17571757
if reflect.is_string(e.base) {
@@ -1788,7 +1788,7 @@ fmt_bit_set :: proc(fi: ^Info, v: any, name: string = "", verb: rune = 'v') {
17881788
return false
17891789
}
17901790
t := runtime.type_info_base(ti)
1791-
#partial switch info in t.variant {
1791+
#partial switch &info in t.variant {
17921792
case runtime.Type_Info_Integer:
17931793
switch info.endianness {
17941794
case .Platform: return false
@@ -1802,7 +1802,7 @@ fmt_bit_set :: proc(fi: ^Info, v: any, name: string = "", verb: rune = 'v') {
18021802
byte_swap :: bits.byte_swap
18031803

18041804
type_info := type_info_of(v.id)
1805-
#partial switch info in type_info.variant {
1805+
#partial switch &info in type_info.variant {
18061806
case runtime.Type_Info_Named:
18071807
val := v
18081808
val.id = info.base.id
@@ -1937,7 +1937,7 @@ fmt_write_array :: proc(fi: ^Info, array_data: rawptr, count: int, elem_size: in
19371937
}
19381938
fi.record_level += 1
19391939
defer fi.record_level -= 1
1940-
1940+
19411941
if fi.hash {
19421942
io.write_byte(fi.writer, '\n', &fi.n)
19431943
defer fmt_write_indent(fi)
@@ -2528,7 +2528,7 @@ fmt_named :: proc(fi: ^Info, v: any, verb: rune, info: runtime.Type_Info_Named)
25282528
}
25292529
}
25302530

2531-
#partial switch b in info.base.variant {
2531+
#partial switch &b in info.base.variant {
25322532
case runtime.Type_Info_Struct:
25332533
fmt_struct(fi, v, verb, b, info.name)
25342534
case runtime.Type_Info_Bit_Field:
@@ -2794,7 +2794,7 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) {
27942794
fi.ignore_user_formatters = false
27952795

27962796
type_info := type_info_of(v.id)
2797-
switch info in type_info.variant {
2797+
switch &info in type_info.variant {
27982798
case runtime.Type_Info_Any: // Ignore
27992799
case runtime.Type_Info_Parameters: // Ignore
28002800

@@ -2819,7 +2819,7 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) {
28192819

28202820
elem := runtime.type_info_base(info.elem)
28212821
if elem != nil {
2822-
#partial switch e in elem.variant {
2822+
#partial switch &e in elem.variant {
28232823
case runtime.Type_Info_Array,
28242824
runtime.Type_Info_Slice,
28252825
runtime.Type_Info_Dynamic_Array,
@@ -2881,7 +2881,7 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) {
28812881
return
28822882
}
28832883

2884-
#partial switch e in elem.variant {
2884+
#partial switch &e in elem.variant {
28852885
case runtime.Type_Info_Integer:
28862886
switch verb {
28872887
case 's', 'q':
@@ -3238,7 +3238,7 @@ fmt_arg :: proc(fi: ^Info, arg: any, verb: rune) {
32383238

32393239
base_arg := arg
32403240
base_arg.id = runtime.typeid_base(base_arg.id)
3241-
switch a in base_arg {
3241+
switch &a in base_arg {
32423242
case bool: fmt_bool(fi, a, verb)
32433243
case b8: fmt_bool(fi, bool(a), verb)
32443244
case b16: fmt_bool(fi, bool(a), verb)

0 commit comments

Comments
 (0)