Skip to content

Commit

Permalink
openapi4filter: improve CSV resp decoder performance (#948)
Browse files Browse the repository at this point in the history
* Improve csv resp decoder performance

Use String Builder for string concatenation

* Update req_resp_decoder.go
  • Loading branch information
mpoqq committed May 11, 2024
1 parent f66e2a1 commit b9f83d9
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions openapi3filter/req_resp_decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1562,7 +1562,7 @@ func zipFileBodyDecoder(body io.Reader, header http.Header, schema *openapi3.Sch
func csvBodyDecoder(body io.Reader, header http.Header, schema *openapi3.SchemaRef, encFn EncodingFn) (interface{}, error) {
r := csv.NewReader(body)

var content string
var sb strings.Builder
for {
record, err := r.Read()
if err == io.EOF {
Expand All @@ -1572,8 +1572,9 @@ func csvBodyDecoder(body io.Reader, header http.Header, schema *openapi3.SchemaR
return nil, err
}

content += strings.Join(record, ",") + "\n"
sb.WriteString(strings.Join(record, ","))
sb.WriteString("\n")
}

return content, nil
return sb.String(), nil
}

0 comments on commit b9f83d9

Please sign in to comment.