diff options
author | Colin Cross <ccross@android.com> | 2024-02-01 12:34:01 -0800 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2024-02-02 15:57:26 -0800 |
commit | 2ef2c356643239b4d42f03a5a95be2ebd7a026ef (patch) | |
tree | 154b7cc54ce4e1cf6c17c40679e9cd1d30ec90d4 | |
parent | dbf18bec9803687acd203f81b89c0d4a0f635958 (diff) | |
download | blueprint-2ef2c356643239b4d42f03a5a95be2ebd7a026ef.tar.gz |
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
-rw-r--r-- | proptools/hash_provider.go | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/proptools/hash_provider.go b/proptools/hash_provider.go index b52a10e..6205bc7 100644 --- a/proptools/hash_provider.go +++ b/proptools/hash_provider.go @@ -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 |