mirror of
https://github.com/restic/restic.git
synced 2026-10-01 00:10:29 +00:00
index: hash blob IDs with maphash.Bytes (#22070)
Avoid constructing a maphash.Hash on every lookup and insert.
This commit is contained in:
@@ -31,7 +31,7 @@ type indexMap struct {
|
||||
buckets []uint
|
||||
numentries uint
|
||||
|
||||
mh maphash.Hash
|
||||
seed maphash.Seed
|
||||
|
||||
blockList hashedArrayTree
|
||||
}
|
||||
@@ -176,15 +176,13 @@ func (m *indexMap) hash(id restic.ID) uint {
|
||||
// While SHA-256 should be collision-resistant, for hash table indices
|
||||
// we use only a few bits of it and finding collisions for those is
|
||||
// much easier than breaking the whole algorithm.
|
||||
mh := maphash.Hash{}
|
||||
mh.SetSeed(m.mh.Seed())
|
||||
_, _ = mh.Write(id[:])
|
||||
h := uint(mh.Sum64())
|
||||
h := uint(maphash.Bytes(m.seed, id[:]))
|
||||
return h & uint(len(m.buckets)-1)
|
||||
}
|
||||
|
||||
func (m *indexMap) init() {
|
||||
const initialBuckets = 64
|
||||
m.seed = maphash.MakeSeed()
|
||||
m.buckets = make([]uint, initialBuckets)
|
||||
// first entry in blockList serves as null byte
|
||||
m.blockList = *newHAT()
|
||||
|
||||
Reference in New Issue
Block a user