Skip to content

Commit

Permalink
Fix to not allocate to the heap when iterating over repeating groups …
Browse files Browse the repository at this point in the history
…in golang 1.22

Verify by running
```golang
go build -gcflags=all=-d=loopvar=2
```
  • Loading branch information
adam-talos committed May 6, 2024
1 parent 813a328 commit ace8544
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1276,8 +1276,8 @@ private int generateGroupEncodeDecode(

// Write the group itself
encode.append(String.format(
"\tfor _, prop := range %1$s.%2$s {\n" +
"\t\tif err := prop.Encode(_m, _w); err != nil {\n" +
"\tfor i := range %1$s.%2$s {\n" +
"\t\tif err := %1$s.%2$s[i].Encode(_m, _w); err != nil {\n" +
"\t\t\treturn err\n" +
"\t\t}\n",
varName,
Expand Down Expand Up @@ -1329,8 +1329,8 @@ private int generateGroupEncodeDecode(

// Range check the group itself
rc.append(String.format(
"\tfor _, prop := range %1$s.%2$s {\n" +
"\t\tif err := prop.RangeCheck(actingVersion, schemaVersion); err != nil {\n" +
"\tfor i := range %1$s.%2$s {\n" +
"\t\tif err := %1$s.%2$s[i].RangeCheck(actingVersion, schemaVersion); err != nil {\n" +
"\t\t\treturn err\n" +
"\t\t}\n" +
"\t}\n",
Expand Down

0 comments on commit ace8544

Please sign in to comment.