diff options
author | Jon Bratseth <bratseth@gmail.com> | 2023-05-08 16:00:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-08 16:00:45 +0200 |
commit | 00cb073f3e60079d55e8043b1f2b0c2eaa4ad604 (patch) | |
tree | ec6705afea22d667a0e38f650f776f0782a182d8 | |
parent | b845cffd474787f7bf215a370b4baa1d828c2848 (diff) | |
parent | dd020e58a51b85fca61bc0f49332e7983c559a13 (diff) |
Merge pull request #27032 from vespa-engine/mpolden/avoid-conversion
Avoid string to []byte conversion
-rw-r--r-- | client/go/internal/vespa/document/http.go | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/client/go/internal/vespa/document/http.go b/client/go/internal/vespa/document/http.go index e9e6d36ff11..e58f0f0fd3d 100644 --- a/client/go/internal/vespa/document/http.go +++ b/client/go/internal/vespa/document/http.go @@ -25,9 +25,11 @@ const ( CompressionAuto Compression = iota CompressionNone CompressionGzip +) - fieldsPrefix = `{"fields":` - fieldsSuffix = "}" +var ( + fieldsPrefix = []byte(`{"fields":`) + fieldsSuffix = []byte("}") ) // Client represents a HTTP client for the /document/v1/ API. @@ -184,9 +186,9 @@ func (c *Client) buffer() *bytes.Buffer { func (c *Client) createRequest(method, url string, body []byte) (*http.Request, error) { // include the outer object expected by /document/v1/ without copying the body r := io.MultiReader( - strings.NewReader(fieldsPrefix), + bytes.NewReader(fieldsPrefix), bytes.NewReader(body), - strings.NewReader(fieldsSuffix), + bytes.NewReader(fieldsSuffix), ) contentLength := int64(len(fieldsPrefix) + len(body) + len(fieldsSuffix)) useGzip := c.options.Compression == CompressionGzip || (c.options.Compression == CompressionAuto && len(body) > 512) @@ -238,7 +240,7 @@ func (c *Client) Send(document Document) Result { } defer resp.Body.Close() elapsed := c.now().Sub(start) - return c.resultWithResponse(resp, req.ContentLength, result, document, elapsed) + return c.resultWithResponse(resp, req.ContentLength, result, elapsed) } func resultWithErr(result Result, err error) Result { @@ -248,7 +250,7 @@ func resultWithErr(result Result, err error) Result { return result } -func (c *Client) resultWithResponse(resp *http.Response, sentBytes int64, result Result, document Document, elapsed time.Duration) Result { +func (c *Client) resultWithResponse(resp *http.Response, sentBytes int64, result Result, elapsed time.Duration) Result { result.HTTPStatus = resp.StatusCode result.Stats.Responses++ result.Stats.ResponsesByCode = map[int]int64{resp.StatusCode: 1} |