Use WriteString in hashProviderInternal
maphash.Hash implements WriteString, which avoids an allocation in order to convert the string to a byte slice. Using the concrete type instead of the io.Writer interface also allows int64Array to be allocated on the stack. Test: SOONG_PROFILE_MEM=/tmp/mem.pprof m nothing Change-Id: I5894f7399c2a232f5f67d7d0724a6115ba2c278f
This commit is contained in:
parent
dbf18bec98
commit
2ef2c35664
1 changed files with 2 additions and 3 deletions
|
@ -19,7 +19,6 @@ import (
|
|||
"encoding/binary"
|
||||
"fmt"
|
||||
"hash/maphash"
|
||||
"io"
|
||||
"math"
|
||||
"reflect"
|
||||
"sort"
|
||||
|
@ -44,7 +43,7 @@ func HashProvider(provider interface{}) (uint64, error) {
|
|||
return hasher.Sum64(), err
|
||||
}
|
||||
|
||||
func hashProviderInternal(hasher io.Writer, v reflect.Value, ptrs map[uintptr]bool) error {
|
||||
func hashProviderInternal(hasher *maphash.Hash, v reflect.Value, ptrs map[uintptr]bool) error {
|
||||
var int64Array [8]byte
|
||||
int64Buf := int64Array[:]
|
||||
binary.LittleEndian.PutUint64(int64Buf, uint64(v.Kind()))
|
||||
|
@ -129,7 +128,7 @@ func hashProviderInternal(hasher io.Writer, v reflect.Value, ptrs map[uintptr]bo
|
|||
}
|
||||
}
|
||||
case reflect.String:
|
||||
hasher.Write([]byte(v.String()))
|
||||
hasher.WriteString(v.String())
|
||||
case reflect.Bool:
|
||||
if v.Bool() {
|
||||
int64Buf[0] = 1
|
||||
|
|
Loading…
Reference in a new issue