mirror of
https://github.com/restic/restic.git
synced 2024-12-23 08:16:36 +00:00
index: remove redundant storage of indexmap size
This commit is contained in:
parent
12141afbad
commit
f1c388c623
1 changed files with 5 additions and 6 deletions
|
@ -2,6 +2,7 @@ package index
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"hash/maphash"
|
"hash/maphash"
|
||||||
|
"math"
|
||||||
|
|
||||||
"github.com/restic/restic/internal/restic"
|
"github.com/restic/restic/internal/restic"
|
||||||
)
|
)
|
||||||
|
@ -17,8 +18,7 @@ import (
|
||||||
// needs to be resized when the table grows, preventing memory usage spikes.
|
// needs to be resized when the table grows, preventing memory usage spikes.
|
||||||
type indexMap struct {
|
type indexMap struct {
|
||||||
// The number of buckets is always a power of two and never zero.
|
// The number of buckets is always a power of two and never zero.
|
||||||
buckets []uint
|
buckets []uint
|
||||||
numentries uint
|
|
||||||
|
|
||||||
mh maphash.Hash
|
mh maphash.Hash
|
||||||
|
|
||||||
|
@ -34,9 +34,9 @@ const (
|
||||||
// using id as the key.
|
// using id as the key.
|
||||||
func (m *indexMap) add(id restic.ID, packIdx int, offset, length uint32, uncompressedLength uint32) {
|
func (m *indexMap) add(id restic.ID, packIdx int, offset, length uint32, uncompressedLength uint32) {
|
||||||
switch {
|
switch {
|
||||||
case m.numentries == 0: // Lazy initialization.
|
case m.len() == math.MaxUint: // Lazy initialization.
|
||||||
m.init()
|
m.init()
|
||||||
case m.numentries >= maxLoad*uint(len(m.buckets)):
|
case m.len() >= maxLoad*uint(len(m.buckets)):
|
||||||
m.grow()
|
m.grow()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,6 @@ func (m *indexMap) add(id restic.ID, packIdx int, offset, length uint32, uncompr
|
||||||
e.uncompressedLength = uncompressedLength
|
e.uncompressedLength = uncompressedLength
|
||||||
|
|
||||||
m.buckets[h] = idx
|
m.buckets[h] = idx
|
||||||
m.numentries++
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// foreach calls fn for all entries in the map, until fn returns false.
|
// foreach calls fn for all entries in the map, until fn returns false.
|
||||||
|
@ -138,7 +137,7 @@ func (m *indexMap) init() {
|
||||||
m.newEntry()
|
m.newEntry()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *indexMap) len() uint { return m.numentries }
|
func (m *indexMap) len() uint { return m.blockList.Size() - 1 }
|
||||||
|
|
||||||
func (m *indexMap) newEntry() (*indexEntry, uint) {
|
func (m *indexMap) newEntry() (*indexEntry, uint) {
|
||||||
return m.blockList.Alloc()
|
return m.blockList.Alloc()
|
||||||
|
|
Loading…
Reference in a new issue