From c59d7e8fba442d48191c7dcba2dbe302d4e98d8e Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 27 Apr 2017 20:36:12 -0700 Subject: [PATCH] gcs: pre-allocate capacity of slice for uncompressed filter values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change will reduce the total number of allocations required to create/store the allocated filter as we’ll now perform a _single_ allocation, rather than one each time the the dynamically size slice reaches capacity. --- gcs/gcs.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gcs/gcs.go b/gcs/gcs.go index 46890c8..1a20794 100644 --- a/gcs/gcs.go +++ b/gcs/gcs.go @@ -76,7 +76,7 @@ func BuildGCSFilter(P uint8, key [KeySize]byte, data [][]byte) (*Filter, error) f.modulusNP = uint64(f.n) * f.modulusP // Build the filter. - var values uint64Slice + values := make(uint64Slice, 0, len(data)) b := bstream.NewBStreamWriter(0) // Insert the hash (modulo N*P) of each data element into a slice and @@ -260,7 +260,7 @@ func (f *Filter) MatchAny(key [KeySize]byte, data [][]byte) (bool, error) { b := bstream.NewBStreamReader(filterData) // Create an uncompressed filter of the search values. - var values uint64Slice + values := make(uint64Slice, 0, len(data)) for _, d := range data { v := siphash.Sum64(d, &key) % f.modulusNP values = append(values, v)