Skip to content

Commit a7d392d

Browse files
authored
Improve csv resp decoder performance
Use String Builder for string concatenation
1 parent f66e2a1 commit a7d392d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

openapi3filter/req_resp_decoder.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,7 +1562,7 @@ func zipFileBodyDecoder(body io.Reader, header http.Header, schema *openapi3.Sch
15621562
func csvBodyDecoder(body io.Reader, header http.Header, schema *openapi3.SchemaRef, encFn EncodingFn) (interface{}, error) {
15631563
r := csv.NewReader(body)
15641564

1565-
var content string
1565+
var sb strings.Builder
15661566
for {
15671567
record, err := r.Read()
15681568
if err == io.EOF {
@@ -1573,7 +1573,9 @@ func csvBodyDecoder(body io.Reader, header http.Header, schema *openapi3.SchemaR
15731573
}
15741574

15751575
content += strings.Join(record, ",") + "\n"
1576+
sb.WriteString(strings.Join(record, ","))
1577+
sb.WriteString("\n")
15761578
}
15771579

1578-
return content, nil
1580+
return sb.String(), nil
15791581
}

0 commit comments

Comments
 (0)