mirror of
https://github.com/restic/restic.git
synced 2025-08-23 15:28:08 +00:00
Prefer mixedCaps over underscore
This commit is contained in:
@@ -54,9 +54,9 @@ func (c Chunk) Reader(r io.ReaderAt) io.Reader {
|
||||
|
||||
// A chunker internally holds everything needed to split content.
|
||||
type Chunker struct {
|
||||
pol Pol
|
||||
pol_shift uint
|
||||
tables *tables
|
||||
pol Pol
|
||||
polShift uint
|
||||
tables *tables
|
||||
|
||||
rd io.Reader
|
||||
closed bool
|
||||
@@ -93,8 +93,8 @@ func New(rd io.Reader, p Pol, bufsize int, hash hash.Hash) *Chunker {
|
||||
// polynomial and reader.
|
||||
func (c *Chunker) Reset(rd io.Reader, p Pol) {
|
||||
c.pol = p
|
||||
c.pol_shift = uint(p.Deg() - 8)
|
||||
c.fill_tables()
|
||||
c.polShift = uint(p.Deg() - 8)
|
||||
c.fillTables()
|
||||
c.rd = rd
|
||||
|
||||
for i := 0; i < WindowSize; i++ {
|
||||
@@ -121,7 +121,7 @@ func (c *Chunker) Reset(rd io.Reader, p Pol) {
|
||||
|
||||
// Calculate out_table and mod_table for optimization. Must be called only
|
||||
// once. This implementation uses a cache in the global variable cache.
|
||||
func (c *Chunker) fill_tables() {
|
||||
func (c *Chunker) fillTables() {
|
||||
// if polynomial hasn't been specified, do not compute anything for now
|
||||
if c.pol == 0 {
|
||||
return
|
||||
@@ -153,9 +153,9 @@ func (c *Chunker) fill_tables() {
|
||||
for b := 0; b < 256; b++ {
|
||||
var h Pol
|
||||
|
||||
h = append_byte(h, byte(b), c.pol)
|
||||
h = appendByte(h, byte(b), c.pol)
|
||||
for i := 0; i < WindowSize-1; i++ {
|
||||
h = append_byte(h, 0, c.pol)
|
||||
h = appendByte(h, 0, c.pol)
|
||||
}
|
||||
c.tables.out[b] = h
|
||||
}
|
||||
@@ -249,7 +249,7 @@ func (c *Chunker) Next() (*Chunk, error) {
|
||||
c.wpos = (c.wpos + 1) % WindowSize
|
||||
|
||||
// c.append(b)
|
||||
index := c.digest >> c.pol_shift
|
||||
index := c.digest >> c.polShift
|
||||
c.digest <<= 8
|
||||
c.digest |= uint64(b)
|
||||
|
||||
@@ -319,7 +319,7 @@ func (c *Chunker) hashDigest() []byte {
|
||||
}
|
||||
|
||||
func (c *Chunker) append(b byte) {
|
||||
index := c.digest >> c.pol_shift
|
||||
index := c.digest >> c.polShift
|
||||
c.digest <<= 8
|
||||
c.digest |= uint64(b)
|
||||
|
||||
@@ -335,7 +335,7 @@ func (c *Chunker) slide(b byte) {
|
||||
c.append(b)
|
||||
}
|
||||
|
||||
func append_byte(hash Pol, b byte, pol Pol) Pol {
|
||||
func appendByte(hash Pol, b byte, pol Pol) Pol {
|
||||
hash <<= 8
|
||||
hash |= Pol(b)
|
||||
|
||||
|
@@ -79,7 +79,7 @@ var chunks2 = []chunk{
|
||||
chunk{chunker.MinSize, 0, parseDigest("07854d2fef297a06ba81685e660c332de36d5d18d546927d30daad6d7fda1541")},
|
||||
}
|
||||
|
||||
func test_with_data(t *testing.T, chnker *chunker.Chunker, testChunks []chunk) []*chunker.Chunk {
|
||||
func testWithData(t *testing.T, chnker *chunker.Chunker, testChunks []chunk) []*chunker.Chunk {
|
||||
chunks := []*chunker.Chunk{}
|
||||
|
||||
pos := uint(0)
|
||||
@@ -133,7 +133,7 @@ func test_with_data(t *testing.T, chnker *chunker.Chunker, testChunks []chunk) [
|
||||
return chunks
|
||||
}
|
||||
|
||||
func get_random(seed, count int) []byte {
|
||||
func getRandom(seed, count int) []byte {
|
||||
buf := make([]byte, count)
|
||||
|
||||
rnd := rand.New(rand.NewSource(23))
|
||||
@@ -150,9 +150,9 @@ func get_random(seed, count int) []byte {
|
||||
|
||||
func TestChunker(t *testing.T) {
|
||||
// setup data source
|
||||
buf := get_random(23, 32*1024*1024)
|
||||
buf := getRandom(23, 32*1024*1024)
|
||||
ch := chunker.New(bytes.NewReader(buf), testPol, *testBufSize, sha256.New())
|
||||
chunks := test_with_data(t, ch, chunks1)
|
||||
chunks := testWithData(t, ch, chunks1)
|
||||
|
||||
// test reader
|
||||
for i, c := range chunks {
|
||||
@@ -180,12 +180,12 @@ func TestChunker(t *testing.T) {
|
||||
buf = bytes.Repeat([]byte{0}, len(chunks2)*chunker.MinSize)
|
||||
ch = chunker.New(bytes.NewReader(buf), testPol, *testBufSize, sha256.New())
|
||||
|
||||
test_with_data(t, ch, chunks2)
|
||||
testWithData(t, ch, chunks2)
|
||||
}
|
||||
|
||||
func TestChunkerWithRandomPolynomial(t *testing.T) {
|
||||
// setup data source
|
||||
buf := get_random(23, 32*1024*1024)
|
||||
buf := getRandom(23, 32*1024*1024)
|
||||
|
||||
// generate a new random polynomial
|
||||
start := time.Now()
|
||||
@@ -210,9 +210,9 @@ func TestChunkerWithRandomPolynomial(t *testing.T) {
|
||||
|
||||
func TestChunkerWithoutHash(t *testing.T) {
|
||||
// setup data source
|
||||
buf := get_random(23, 32*1024*1024)
|
||||
buf := getRandom(23, 32*1024*1024)
|
||||
ch := chunker.New(bytes.NewReader(buf), testPol, *testBufSize, nil)
|
||||
chunks := test_with_data(t, ch, chunks1)
|
||||
chunks := testWithData(t, ch, chunks1)
|
||||
|
||||
// test reader
|
||||
for i, c := range chunks {
|
||||
@@ -243,17 +243,17 @@ func TestChunkerWithoutHash(t *testing.T) {
|
||||
buf = bytes.Repeat([]byte{0}, len(chunks2)*chunker.MinSize)
|
||||
ch = chunker.New(bytes.NewReader(buf), testPol, *testBufSize, sha256.New())
|
||||
|
||||
test_with_data(t, ch, chunks2)
|
||||
testWithData(t, ch, chunks2)
|
||||
}
|
||||
|
||||
func TestChunkerReuse(t *testing.T) {
|
||||
// test multiple uses of the same chunker
|
||||
ch := chunker.New(nil, testPol, *testBufSize, sha256.New())
|
||||
buf := get_random(23, 32*1024*1024)
|
||||
buf := getRandom(23, 32*1024*1024)
|
||||
|
||||
for i := 0; i < 4; i++ {
|
||||
ch.Reset(bytes.NewReader(buf), testPol)
|
||||
test_with_data(t, ch, chunks1)
|
||||
testWithData(t, ch, chunks1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@ func benchmarkChunker(b *testing.B, hash hash.Hash) {
|
||||
rd = f
|
||||
} else {
|
||||
size = 10 * 1024 * 1024
|
||||
rd = bytes.NewReader(get_random(23, size))
|
||||
rd = bytes.NewReader(getRandom(23, size))
|
||||
}
|
||||
|
||||
ch := chunker.New(rd, testPol, *testBufSize, hash)
|
||||
|
Reference in New Issue
Block a user