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:
Dominik Honnef
2022-06-28 17:09:19 +02:00
committed by Elias Naur
parent 4d593927ae
commit e21c665e70
+3 -1
View File
@@ -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()
}