aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/klauspost/compress/zstd/bitreader.go
diff options
context:
space:
mode:
authordependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>2024-09-10 14:20:24 +0000
committerTaras Madan <tarasmadan@google.com>2024-09-11 10:38:33 +0000
commit86905c52379d40fda560d52434c8fe1c498b65b5 (patch)
treefe4e16cf3a3ebc4afce8935f75a776048931547a /vendor/github.com/klauspost/compress/zstd/bitreader.go
parent9326a104643f33f9a9bde19bd9558496e972edff (diff)
mod: bump github.com/prometheus/client_golang from 1.19.1 to 1.20.3
Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.19.1 to 1.20.3. - [Release notes](https://github.com/prometheus/client_golang/releases) - [Changelog](https://github.com/prometheus/client_golang/blob/v1.20.3/CHANGELOG.md) - [Commits](https://github.com/prometheus/client_golang/compare/v1.19.1...v1.20.3) --- updated-dependencies: - dependency-name: github.com/prometheus/client_golang dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
Diffstat (limited to 'vendor/github.com/klauspost/compress/zstd/bitreader.go')
-rw-r--r--vendor/github.com/klauspost/compress/zstd/bitreader.go34
1 files changed, 15 insertions, 19 deletions
diff --git a/vendor/github.com/klauspost/compress/zstd/bitreader.go b/vendor/github.com/klauspost/compress/zstd/bitreader.go
index 97299d499..25ca98394 100644
--- a/vendor/github.com/klauspost/compress/zstd/bitreader.go
+++ b/vendor/github.com/klauspost/compress/zstd/bitreader.go
@@ -17,7 +17,6 @@ import (
// for aligning the input.
type bitReader struct {
in []byte
- off uint // next byte to read is at in[off - 1]
value uint64 // Maybe use [16]byte, but shifting is awkward.
bitsRead uint8
}
@@ -28,7 +27,6 @@ func (b *bitReader) init(in []byte) error {
return errors.New("corrupt stream: too short")
}
b.in = in
- b.off = uint(len(in))
// The highest bit of the last byte indicates where to start
v := in[len(in)-1]
if v == 0 {
@@ -69,21 +67,19 @@ func (b *bitReader) fillFast() {
if b.bitsRead < 32 {
return
}
- // 2 bounds checks.
- v := b.in[b.off-4:]
- v = v[:4]
+ v := b.in[len(b.in)-4:]
+ b.in = b.in[:len(b.in)-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:])
+ v := b.in[len(b.in)-8:]
+ b.in = b.in[:len(b.in)-8]
+ b.value = binary.LittleEndian.Uint64(v)
b.bitsRead = 0
- b.off -= 8
}
// fill() will make sure at least 32 bits are available.
@@ -91,25 +87,25 @@ func (b *bitReader) fill() {
if b.bitsRead < 32 {
return
}
- if b.off >= 4 {
- v := b.in[b.off-4:]
- v = v[:4]
+ if len(b.in) >= 4 {
+ v := b.in[len(b.in)-4:]
+ b.in = b.in[:len(b.in)-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
return
}
- for b.off > 0 {
- b.value = (b.value << 8) | uint64(b.in[b.off-1])
- b.bitsRead -= 8
- b.off--
+
+ b.bitsRead -= uint8(8 * len(b.in))
+ for len(b.in) > 0 {
+ b.value = (b.value << 8) | uint64(b.in[len(b.in)-1])
+ b.in = b.in[:len(b.in)-1]
}
}
// finished returns true if all bits have been read from the bit stream.
func (b *bitReader) finished() bool {
- return b.off == 0 && b.bitsRead >= 64
+ return len(b.in) == 0 && b.bitsRead >= 64
}
// overread returns true if more bits have been requested than is on the stream.
@@ -119,7 +115,7 @@ func (b *bitReader) overread() bool {
// remain returns the number of bits remaining.
func (b *bitReader) remain() uint {
- return b.off*8 + 64 - uint(b.bitsRead)
+ return 8*uint(len(b.in)) + 64 - uint(b.bitsRead)
}
// close the bitstream and returns an error if out-of-buffer reads occurred.