Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gen/maxsize.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,9 @@ func (s *maxSizeGen) Execute(p Elem) ([]string, error) {
// to not affect other code that will use p.
p = p.Copy()

s.p.comment("MaxSize returns a maximum valid message size for this message type")

if IsDangling(p) {
baseType := p.(*BaseElem).IdentName
s.p.comment(strings.TrimSuffix(getMaxSizeMethod(baseType), "()") + " returns a maximum valid message size for this message type")

Copilot AI Nov 14, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The expression strings.TrimSuffix(getMaxSizeMethod(baseType), \"()\") is duplicated on lines 97 and 111. Consider extracting this into a helper function to improve maintainability and reduce code duplication.

Copilot uses AI. Check for mistakes.
s.p.printf("\nfunc %s int{", getMaxSizeMethod(p.TypeName()))
s.p.printf("\n return %s", getMaxSizeMethod(baseType))
s.p.printf("\n}")
Expand All @@ -109,6 +108,7 @@ func (s *maxSizeGen) Execute(p Elem) ([]string, error) {
s.halted = false

// receiver := imutMethodReceiver(p)
s.p.comment(strings.TrimSuffix(getMaxSizeMethod(p.TypeName()), "()") + " returns a maximum valid message size for this message type")
s.p.printf("\nfunc %s (s int) {", getMaxSizeMethod(p.TypeName()))
s.state = assignM
next(s, p)
Expand Down
12 changes: 6 additions & 6 deletions printer/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ func generate(f *parse.FileSet, mode gen.Method) (*bytes.Buffer, *bytes.Buffer,
}

func writePkgHeader(b *bytes.Buffer, name string) {
b.WriteString("package ")
b.WriteString(name)
b.WriteByte('\n')
// write generated code marker
// https://github.com/tinylib/msgp/issues/229
// https://golang.org/s/generatedcode
b.WriteString("// Code generated by github.com/algorand/msgp DO NOT EDIT.\n\n")
b.WriteString(`// Code generated by github.com/algorand/msgp DO NOT EDIT.

package ` + name + `

`)
}

func writeImportHeader(b *bytes.Buffer, imports ...string) {
Expand All @@ -163,6 +163,6 @@ func writeImportHeader(b *bytes.Buffer, imports ...string) {
}

func writeBuildHeader(b *bytes.Buffer, buildHeaders []string) {
headers := fmt.Sprintf("//go:build %s\n// +build %s\n\n", strings.Join(buildHeaders, " "), strings.Join(buildHeaders, " "))
headers := fmt.Sprintf("//go:build %s\n\n", strings.Join(buildHeaders, " "))
b.WriteString(headers)
}
2 changes: 1 addition & 1 deletion printer/print_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ func TestWriteBuildHeader(t *testing.T) {
testBuf := bytes.NewBuffer(make([]byte, 0, 4096))
buildHeaders := []string{"foobar"}
expectedBuf := bytes.NewBuffer(make([]byte, 0, 4096))
expectedBuf.WriteString("//go:build foobar\n// +build foobar\n\n")
expectedBuf.WriteString("//go:build foobar\n\n")

writeBuildHeader(testBuf, buildHeaders)

Expand Down