summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2023-05-08 21:16:13 +0200
committerMartin Polden <mpolden@mpolden.no>2023-05-08 21:16:13 +0200
commit52f0b05f2aeeafa89a6af2595683013705de07d1 (patch)
tree82f1f90eb994dd10416edf57ed4e8008a271c311
parentafa043fd3f301ac12b107a722ef8aff861a0e8dc (diff)
Initialize buffer with wanted size
-rw-r--r--client/go/internal/vespa/document/http.go7
1 files changed, 3 insertions, 4 deletions
diff --git a/client/go/internal/vespa/document/http.go b/client/go/internal/vespa/document/http.go
index e58f0f0fd3d..d65eb4157a9 100644
--- a/client/go/internal/vespa/document/http.go
+++ b/client/go/internal/vespa/document/http.go
@@ -193,9 +193,8 @@ func (c *Client) createRequest(method, url string, body []byte) (*http.Request,
contentLength := int64(len(fieldsPrefix) + len(body) + len(fieldsSuffix))
useGzip := c.options.Compression == CompressionGzip || (c.options.Compression == CompressionAuto && len(body) > 512)
if useGzip {
- var buf bytes.Buffer
- buf.Grow(1024)
- w := c.gzipWriter(&buf)
+ buf := bytes.NewBuffer(make([]byte, 0, 1024))
+ w := c.gzipWriter(buf)
if _, err := io.Copy(w, r); err != nil {
return nil, err
}
@@ -203,7 +202,7 @@ func (c *Client) createRequest(method, url string, body []byte) (*http.Request,
return nil, err
}
c.gzippers.Put(w)
- r = &buf
+ r = buf
contentLength = int64(buf.Len())
}
req, err := http.NewRequest(method, url, r)