summaryrefslogtreecommitdiff
path: root/vendor/github.com/klauspost/compress/zstd/bitreader.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-06-17 20:16:44 +0200
committerGitHub <noreply@github.com>2020-06-17 20:16:44 +0200
commit6645e0d6f376b0dbd2bf82b3c708ceb20a6ad920 (patch)
treeb0e7ad7e27d8608f061226497fbdced2102ce054 /vendor/github.com/klauspost/compress/zstd/bitreader.go
parentf293606480669acea375c53de1e2c81044313c05 (diff)
parentac4f4b14829b66f6aa24b75128bd68e3a5fb53b9 (diff)
downloadpodman-6645e0d6f376b0dbd2bf82b3c708ceb20a6ad920.tar.gz
podman-6645e0d6f376b0dbd2bf82b3c708ceb20a6ad920.tar.bz2
podman-6645e0d6f376b0dbd2bf82b3c708ceb20a6ad920.zip
Merge pull request #6648 from vrothberg/vendor-image
vendor github.com/containers/image/v5@v5.5.1
Diffstat (limited to 'vendor/github.com/klauspost/compress/zstd/bitreader.go')
-rw-r--r--vendor/github.com/klauspost/compress/zstd/bitreader.go25
1 files changed, 20 insertions, 5 deletions
diff --git a/vendor/github.com/klauspost/compress/zstd/bitreader.go b/vendor/github.com/klauspost/compress/zstd/bitreader.go
index 15d79d439..854458537 100644
--- a/vendor/github.com/klauspost/compress/zstd/bitreader.go
+++ b/vendor/github.com/klauspost/compress/zstd/bitreader.go
@@ -5,6 +5,7 @@
package zstd
import (
+ "encoding/binary"
"errors"
"io"
"math/bits"
@@ -34,8 +35,12 @@ func (b *bitReader) init(in []byte) error {
}
b.bitsRead = 64
b.value = 0
- b.fill()
- b.fill()
+ if len(in) >= 8 {
+ b.fillFastStart()
+ } else {
+ b.fill()
+ b.fill()
+ }
b.bitsRead += 8 - uint8(highBits(uint32(v)))
return nil
}
@@ -63,21 +68,31 @@ func (b *bitReader) fillFast() {
if b.bitsRead < 32 {
return
}
- // Do single re-slice to avoid bounds checks.
- v := b.in[b.off-4 : b.off]
+ // 2 bounds checks.
+ v := b.in[b.off-4:]
+ v = v[:4]
low := (uint32(v[0])) | (uint32(v[1]) << 8) | (uint32(v[2]) << 16) | (uint32(v[3]) << 24)
b.value = (b.value << 32) | uint64(low)
b.bitsRead -= 32
b.off -= 4
}
+// fillFastStart() assumes the bitreader is empty and there is at least 8 bytes to read.
+func (b *bitReader) fillFastStart() {
+ // Do single re-slice to avoid bounds checks.
+ b.value = binary.LittleEndian.Uint64(b.in[b.off-8:])
+ b.bitsRead = 0
+ b.off -= 8
+}
+
// fill() will make sure at least 32 bits are available.
func (b *bitReader) fill() {
if b.bitsRead < 32 {
return
}
if b.off >= 4 {
- v := b.in[b.off-4 : b.off]
+ v := b.in[b.off-4:]
+ v = v[:4]
low := (uint32(v[0])) | (uint32(v[1]) << 8) | (uint32(v[2]) << 16) | (uint32(v[3]) << 24)
b.value = (b.value << 32) | uint64(low)
b.bitsRead -= 32