Skip to content

Commit 86a9489

Browse files
authored
gzhttp: remove redundant err check in zstdReader (#1090)
1 parent ad4a030 commit 86a9489

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

gzhttp/transport.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,10 @@ func lower(b byte) byte {
196196
var zstdReaderPool sync.Pool
197197

198198
// zstdReader wraps a response body so it can lazily
199-
// call gzip.NewReader on the first call to Read
199+
// call zstd.NewReader on the first call to Read
200200
type zstdReader struct {
201201
body io.ReadCloser // underlying HTTP/1 response body framing
202-
zr *zstd.Decoder // lazily-initialized gzip reader
202+
zr *zstd.Decoder // lazily-initialized zstd reader
203203
zerr error // any error from zstd.NewReader; sticky
204204
}
205205

@@ -208,14 +208,12 @@ func (zr *zstdReader) Read(p []byte) (n int, err error) {
208208
return 0, zr.zerr
209209
}
210210
if zr.zr == nil {
211-
if zr.zerr == nil {
212-
reader, ok := zstdReaderPool.Get().(*zstd.Decoder)
213-
if ok {
214-
zr.zerr = reader.Reset(zr.body)
215-
zr.zr = reader
216-
} else {
217-
zr.zr, zr.zerr = zstd.NewReader(zr.body, zstd.WithDecoderLowmem(true), zstd.WithDecoderMaxWindow(32<<20), zstd.WithDecoderConcurrency(1))
218-
}
211+
reader, ok := zstdReaderPool.Get().(*zstd.Decoder)
212+
if ok {
213+
zr.zerr = reader.Reset(zr.body)
214+
zr.zr = reader
215+
} else {
216+
zr.zr, zr.zerr = zstd.NewReader(zr.body, zstd.WithDecoderLowmem(true), zstd.WithDecoderMaxWindow(32<<20), zstd.WithDecoderConcurrency(1))
219217
}
220218
if zr.zerr != nil {
221219
return 0, zr.zerr

0 commit comments

Comments
 (0)