From 2a85cb7142e6af5439d6d9cf2f6ddada04b4797e Mon Sep 17 00:00:00 2001 From: mpl Date: Sat, 23 Feb 2019 01:07:23 +0100 Subject: [PATCH] internal/rollsum: replace with go4.org/rollsum Fixes #1253 Change-Id: I64aac5739a18d2e19494881dcceff9d43355fac2 --- cmd/pk/splits.go | 2 +- go.mod | 2 +- go.sum | 4 +++- pkg/fileembed/genfileembed/genfileembed.go | 2 +- pkg/schema/filewriter.go | 2 +- .../rollsum => vendor/go4.org}/rollsum.go | 20 +++++++++---------- .../go4.org}/rollsum_test.go | 0 7 files changed, 17 insertions(+), 15 deletions(-) rename {internal/rollsum => vendor/go4.org}/rollsum.go (85%) rename {internal/rollsum => vendor/go4.org}/rollsum_test.go (100%) diff --git a/cmd/pk/splits.go b/cmd/pk/splits.go index 1214ec48f..f48e8a0c6 100644 --- a/cmd/pk/splits.go +++ b/cmd/pk/splits.go @@ -24,7 +24,7 @@ import ( "os" "strings" - "perkeep.org/internal/rollsum" + "go4.org/rollsum" ) type span struct { diff --git a/go.mod b/go.mod index 927bbf9f7..94d005738 100644 --- a/go.mod +++ b/go.mod @@ -51,7 +51,7 @@ require ( github.com/syndtr/goleveldb v0.0.0-20180608030153-db3ee9ee8931 github.com/tgulacsi/picago v0.0.0-20171229130838-9e1ac2306c70 github.com/tomnomnom/linkheader v0.0.0-20160328204959-6953a30d4443 - go4.org v0.0.0-20180413184151-a2a47940e6bc + go4.org v0.0.0-20190218023631-ce4c26f7be8e golang.org/x/crypto v0.0.0-20180723164146-c126467f60eb golang.org/x/image v0.0.0-20171214225156-12117c17ca67 golang.org/x/net v0.0.0-20171212005608-d866cfc389ce diff --git a/go.sum b/go.sum index 630a1ec68..09f5d233e 100644 --- a/go.sum +++ b/go.sum @@ -109,6 +109,8 @@ github.com/tomnomnom/linkheader v0.0.0-20160328204959-6953a30d4443 h1:ovXpn6PhLk github.com/tomnomnom/linkheader v0.0.0-20160328204959-6953a30d4443/go.mod h1:iFyPdL66DjUD96XmzVL3ZntbzcflLnznH0fr99w5VqE= go4.org v0.0.0-20180413184151-a2a47940e6bc h1:poolp8Py6LYswolW85K75U8L42AkHWBv/+ewlI/ZHA0= go4.org v0.0.0-20180413184151-a2a47940e6bc/go.mod h1:MkTOUMDaeVYJUOUsaDXIhWPZYa1yOyC1qaOBpL57BhE= +go4.org v0.0.0-20190218023631-ce4c26f7be8e h1:m9LfARr2VIOW0vsV19kEKp/sWQvZnGobA8JHui/XJoY= +go4.org v0.0.0-20190218023631-ce4c26f7be8e/go.mod h1:MkTOUMDaeVYJUOUsaDXIhWPZYa1yOyC1qaOBpL57BhE= golang.org/x/crypto v0.0.0-20180606015541-b47b15873692 h1:O9W34I8ef1ifsNUjJoqTsouE17HSL5RVJNn9pLMf7Og= golang.org/x/crypto v0.0.0-20180606015541-b47b15873692/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180723164146-c126467f60eb h1:Ah9YqXLj6fEgeKqcmBuLCbAsrF3ScD7dJ/bYM0C6tXI= @@ -142,7 +144,7 @@ gopkg.in/mgo.v2 v2.0.0-20160818020120-3f83fa500528 h1:/saqWwm73dLmuzbNhe92F0QsZ/ gopkg.in/mgo.v2 v2.0.0-20160818020120-3f83fa500528/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA= honnef.co/go/js/dom v0.0.0-20160310112645-24aa052bc5c6 h1:tt1qVqcZt6cRcvoUTMBbCnLEkjm2o4WGMkF0mE9Fx3s= honnef.co/go/js/dom v0.0.0-20160310112645-24aa052bc5c6/go.mod h1:sUMDUKNB2ZcVjt92UnLy3cdGs+wDAcrPdV3JP6sVgA4= -myitcv.io v0.0.0-20180717150903-bf2c84553c78 h1:Hc0gqDZHlmLo4xohfx/0/azkaztHW1CAFSXa4ygFoqI= +myitcv.io v0.0.0-20180717150903-bf2c84553c78 h1:ISoxJY6pqBP0HmQEwjNldhzlyfZAswY0yTjZZRfGYXk= myitcv.io v0.0.0-20180717150903-bf2c84553c78/go.mod h1:eZGravSD0Y1vesgGXvhvceVMg34vGeRCYvzHtT9nX1k= rsc.io/pdf v0.0.0-20170302045715-1d34785eb915 h1:Deg3CmTFQ+bWVBNEjlhrfNsSl2/YI20/XNKCxBX5aVg= rsc.io/pdf v0.0.0-20170302045715-1d34785eb915/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= diff --git a/pkg/fileembed/genfileembed/genfileembed.go b/pkg/fileembed/genfileembed/genfileembed.go index 06f78d851..2fc679eec 100644 --- a/pkg/fileembed/genfileembed/genfileembed.go +++ b/pkg/fileembed/genfileembed/genfileembed.go @@ -37,7 +37,7 @@ import ( "strings" "time" - "perkeep.org/internal/rollsum" + "go4.org/rollsum" ) var ( diff --git a/pkg/schema/filewriter.go b/pkg/schema/filewriter.go index e28743fb2..8f9abafce 100644 --- a/pkg/schema/filewriter.go +++ b/pkg/schema/filewriter.go @@ -26,7 +26,7 @@ import ( "strings" "time" - "perkeep.org/internal/rollsum" + "go4.org/rollsum" "perkeep.org/pkg/blob" "perkeep.org/pkg/blobserver" diff --git a/internal/rollsum/rollsum.go b/vendor/go4.org/rollsum.go similarity index 85% rename from internal/rollsum/rollsum.go rename to vendor/go4.org/rollsum.go index 8a9563dad..47019614d 100644 --- a/internal/rollsum/rollsum.go +++ b/vendor/go4.org/rollsum.go @@ -19,7 +19,11 @@ limitations under the License. // // The bup project is at https://github.com/apenwarr/bup and its splitting in // particular is at https://github.com/apenwarr/bup/blob/master/lib/bup/bupsplit.c -package rollsum // import "perkeep.org/internal/rollsum" +package rollsum // import "go4.org/rollsum" + +import ( + "math/bits" +) const windowSize = 64 // Roll assumes windowSize is a power of 2 const charOffset = 31 @@ -46,6 +50,7 @@ func (rs *RollSum) add(drop, add uint32) { rs.s2 += s1 - uint32(windowSize)*(drop+charOffset) } +// Roll adds ch to the rolling sum. func (rs *RollSum) Roll(ch byte) { wp := &rs.window[rs.wofs] rs.add(uint32(*wp), uint32(ch)) @@ -53,13 +58,13 @@ func (rs *RollSum) Roll(ch byte) { rs.wofs = (rs.wofs + 1) & (windowSize - 1) } -// OnSplit returns whether at least 13 consecutive trailing bits of +// OnSplit reports whether at least 13 consecutive trailing bits of // the current checksum are set the same way. func (rs *RollSum) OnSplit() bool { return (rs.s2 & (blobSize - 1)) == ((^0) & (blobSize - 1)) } -// OnSplitWithBits returns whether at least n consecutive trailing bits +// OnSplitWithBits reports whether at least n consecutive trailing bits // of the current checksum are set the same way. func (rs *RollSum) OnSplitWithBits(n uint32) bool { mask := (uint32(1) << n) - 1 @@ -67,13 +72,8 @@ func (rs *RollSum) OnSplitWithBits(n uint32) bool { } func (rs *RollSum) Bits() int { - bits := blobBits - rsum := rs.Digest() - rsum >>= blobBits - for ; (rsum>>1)&1 != 0; bits++ { - rsum >>= 1 - } - return bits + rsum := rs.Digest() >> (blobBits + 1) + return blobBits + bits.TrailingZeros32(^rsum) } func (rs *RollSum) Digest() uint32 { diff --git a/internal/rollsum/rollsum_test.go b/vendor/go4.org/rollsum_test.go similarity index 100% rename from internal/rollsum/rollsum_test.go rename to vendor/go4.org/rollsum_test.go