summaryrefslogtreecommitdiff
path: root/vendor/github.com/klauspost/compress/flate/level1.go
diff options
context:
space:
mode:
authorAshley Cui <acui@redhat.com>2022-02-28 16:23:19 -0500
committerAshley Cui <acui@redhat.com>2022-02-28 16:23:26 -0500
commit569319d3970c2e94e4c6586d4bb17e5cfc108fdf (patch)
tree843f87290ef42f8eee7e9d5963fa916a3172e4ea /vendor/github.com/klauspost/compress/flate/level1.go
parent2225c65f74b3358d810183558185a6344ef686ac (diff)
downloadpodman-569319d3970c2e94e4c6586d4bb17e5cfc108fdf.tar.gz
podman-569319d3970c2e94e4c6586d4bb17e5cfc108fdf.tar.bz2
podman-569319d3970c2e94e4c6586d4bb17e5cfc108fdf.zip
Vendor in containers/common@main
Signed-off-by: Ashley Cui <acui@redhat.com>
Diffstat (limited to 'vendor/github.com/klauspost/compress/flate/level1.go')
-rw-r--r--vendor/github.com/klauspost/compress/flate/level1.go56
1 files changed, 53 insertions, 3 deletions
diff --git a/vendor/github.com/klauspost/compress/flate/level1.go b/vendor/github.com/klauspost/compress/flate/level1.go
index 1e5eea396..0022c8bb6 100644
--- a/vendor/github.com/klauspost/compress/flate/level1.go
+++ b/vendor/github.com/klauspost/compress/flate/level1.go
@@ -1,6 +1,10 @@
package flate
-import "fmt"
+import (
+ "encoding/binary"
+ "fmt"
+ "math/bits"
+)
// fastGen maintains the table for matches,
// and the previous byte block for level 2.
@@ -116,7 +120,32 @@ func (e *fastEncL1) Encode(dst *tokens, src []byte) {
// Extend the 4-byte match as long as possible.
t := candidate.offset - e.cur
- l := e.matchlenLong(s+4, t+4, src) + 4
+ var l = int32(4)
+ if false {
+ l = e.matchlenLong(s+4, t+4, src) + 4
+ } else {
+ // inlined:
+ a := src[s+4:]
+ b := src[t+4:]
+ for len(a) >= 8 {
+ if diff := binary.LittleEndian.Uint64(a) ^ binary.LittleEndian.Uint64(b); diff != 0 {
+ l += int32(bits.TrailingZeros64(diff) >> 3)
+ break
+ }
+ l += 8
+ a = a[8:]
+ b = b[8:]
+ }
+ if len(a) < 8 {
+ b = b[:len(a)]
+ for i := range a {
+ if a[i] != b[i] {
+ break
+ }
+ l++
+ }
+ }
+ }
// Extend backwards
for t > 0 && s > nextEmit && src[t-1] == src[s-1] {
@@ -129,7 +158,28 @@ func (e *fastEncL1) Encode(dst *tokens, src []byte) {
}
// Save the match found
- dst.AddMatchLong(l, uint32(s-t-baseMatchOffset))
+ if false {
+ dst.AddMatchLong(l, uint32(s-t-baseMatchOffset))
+ } else {
+ // Inlined...
+ xoffset := uint32(s - t - baseMatchOffset)
+ xlength := l
+ oc := offsetCode(xoffset)
+ xoffset |= oc << 16
+ for xlength > 0 {
+ xl := xlength
+ if xl > 258 {
+ // We need to have at least baseMatchLength left over for next loop.
+ xl = 258 - baseMatchLength
+ }
+ xlength -= xl
+ xl -= baseMatchLength
+ dst.extraHist[lengthCodes1[uint8(xl)]]++
+ dst.offHist[oc]++
+ dst.tokens[dst.n] = token(matchType | uint32(xl)<<lengthShift | xoffset)
+ dst.n++
+ }
+ }
s += l
nextEmit = s
if nextS >= s {