diff options
| author | 2026-03-05 17:36:48 +0800 | |
|---|---|---|
| committer | 2026-03-05 18:38:29 +0800 | |
| commit | beabb6085d42cbb961e3a5dc217fdd840fee4b0d (patch) | |
| tree | 64ea334e74925284228254631bd4e8bea89001d2 /internal/compress/flate/matchlen_generic.go | |
| parent | internal/zlib: Unexport Reset (diff) | |
internal/compress: Import flate and such from klauspost/compress
Diffstat (limited to 'internal/compress/flate/matchlen_generic.go')
| -rw-r--r-- | internal/compress/flate/matchlen_generic.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/internal/compress/flate/matchlen_generic.go b/internal/compress/flate/matchlen_generic.go new file mode 100644 index 00000000..63c0637d --- /dev/null +++ b/internal/compress/flate/matchlen_generic.go @@ -0,0 +1,34 @@ +// Copyright 2019+ Klaus Post. All rights reserved. +// License information can be found in the LICENSE file. + +package flate + +import ( + "math/bits" + + "codeberg.org/lindenii/furgit/internal/compress/internal/le" +) + +// matchLen returns the maximum common prefix length of a and b. +// a must be the shortest of the two. +func matchLen(a, b []byte) (n int) { + left := len(a) + for left >= 8 { + diff := le.Load64(a, n) ^ le.Load64(b, n) + if diff != 0 { + return n + bits.TrailingZeros64(diff)>>3 + } + n += 8 + left -= 8 + } + + a = a[n:] + b = b[n:] + for i := range a { + if a[i] != b[i] { + break + } + n++ + } + return n +} |
