mirror of
https://github.com/octoleo/restic.git
synced 2024-11-17 18:45:15 +00:00
22 lines
388 B
Go
22 lines
388 B
Go
package restic
|
|
|
|
import "bytes"
|
|
|
|
// ZeroPrefixLen returns the length of the longest all-zero prefix of p.
|
|
func ZeroPrefixLen(p []byte) (n int) {
|
|
// First skip 1kB-sized blocks, for speed.
|
|
var zeros [1024]byte
|
|
|
|
for len(p) >= len(zeros) && bytes.Equal(p[:len(zeros)], zeros[:]) {
|
|
p = p[len(zeros):]
|
|
n += len(zeros)
|
|
}
|
|
|
|
for len(p) > 0 && p[0] == 0 {
|
|
p = p[1:]
|
|
n++
|
|
}
|
|
|
|
return n
|
|
}
|