mirror of
https://github.com/restic/restic.git
synced 2026-11-24 15:14:55 +00:00
Remove chunker.Reset() and chunker pool
This commit is contained in:
1 parent
c57c4f0b8f
commit
282c4379db
5 files changed
+32
-93
No files matched your search
+17
-26
@@ -17,6 +17,9 @@ const (
|
||||
// aim to create chunks of 20 bits or about 1MiB on average.
|
||||
averageBits = 20
|
||||
|
||||
// default buffer size
|
||||
bufSize = 512 * KiB
|
||||
|
||||
// MinSize is the minimal size of a chunk.
|
||||
MinSize = 512 * KiB
|
||||
// MaxSize is the maximal size of a chunk.
|
||||
@@ -81,36 +84,33 @@ type Chunker struct {
|
||||
|
||||
// New returns a new Chunker based on polynomial p that reads from data from rd
|
||||
// with bufsize and pass all data to hash along the way.
|
||||
func New(rd io.Reader, p Pol, bufsize int, hash hash.Hash) *Chunker {
|
||||
func New(rd io.Reader, pol Pol, h hash.Hash) *Chunker {
|
||||
c := &Chunker{
|
||||
buf: make([]byte, bufsize),
|
||||
h: hash,
|
||||
buf: make([]byte, bufSize),
|
||||
h: h,
|
||||
pol: pol,
|
||||
rd: rd,
|
||||
}
|
||||
c.Reset(rd, p)
|
||||
|
||||
c.reset()
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
// Reset restarts a chunker so that it can be reused with a different
|
||||
// polynomial and reader.
|
||||
func (c *Chunker) Reset(rd io.Reader, p Pol) {
|
||||
c.pol = p
|
||||
c.polShift = uint(p.Deg() - 8)
|
||||
func (c *Chunker) reset() {
|
||||
c.polShift = uint(c.pol.Deg() - 8)
|
||||
c.fillTables()
|
||||
c.rd = rd
|
||||
|
||||
for i := 0; i < windowSize; i++ {
|
||||
c.window[i] = 0
|
||||
}
|
||||
|
||||
c.closed = false
|
||||
c.digest = 0
|
||||
c.wpos = 0
|
||||
c.pos = 0
|
||||
c.start = 0
|
||||
c.count = 0
|
||||
|
||||
if p != 0 {
|
||||
c.slide(1)
|
||||
}
|
||||
c.slide(1)
|
||||
c.start = c.pos
|
||||
|
||||
if c.h != nil {
|
||||
c.h.Reset()
|
||||
@@ -276,16 +276,7 @@ func (c *Chunker) Next() (*Chunk, error) {
|
||||
Digest: c.hashDigest(),
|
||||
}
|
||||
|
||||
if c.h != nil {
|
||||
c.h.Reset()
|
||||
}
|
||||
|
||||
// reset chunker, but keep position
|
||||
pos := c.pos
|
||||
c.Reset(c.rd, c.pol)
|
||||
c.pos = pos
|
||||
c.start = pos
|
||||
c.pre = MinSize - windowSize
|
||||
c.reset()
|
||||
|
||||
return chunk, nil
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user