mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
text: optimize faceCache.hashGIDs
Use binary.LittleEndian directly instead of going through the binary.Write indirection. This allows the following optimizations to occur: - We can reuse our own byte slice between iterations - We don't have to put g.ID in an interface value - h doesn't escape - PutUint32 gets inlined On top of that, the argument to maphash.Hash.Write doesn't escape, so b doesn't move to the heap. Signed-off-by: Dominik Honnef <dominik@honnef.co>
This commit is contained in:
committed by
Elias Naur
parent
4d593927ae
commit
e21c665e70
+3
-1
@@ -156,8 +156,10 @@ func (f *faceCache) hashGIDs(layout Layout) uint64 {
|
||||
}
|
||||
var h maphash.Hash
|
||||
h.SetSeed(f.seed)
|
||||
var b [4]byte
|
||||
for _, g := range layout.Glyphs {
|
||||
binary.Write(&h, binary.LittleEndian, g.ID)
|
||||
binary.LittleEndian.PutUint32(b[:], uint32(g.ID))
|
||||
h.Write(b[:])
|
||||
}
|
||||
return h.Sum64()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user