From 94370e0b464f1f48a6b5b00975092245652b6d48 Mon Sep 17 00:00:00 2001 From: Shane Hansen Date: Fri, 29 Mar 2019 15:12:32 -0700 Subject: [PATCH 1/2] Lift structs to higher scope Small performance improvement (27%) by re-using search result structs. Likely the original C version relied on stack allocation here. --- backward_references.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backward_references.go b/backward_references.go index 0ac5cb8..b22275b 100644 --- a/backward_references.go +++ b/backward_references.go @@ -57,11 +57,12 @@ func createBackwardReferences(num_bytes uint, position uint, ringbuffer []byte, /* Minimum score to accept a backward reference. */ hasher.PrepareDistanceCache(dist_cache) + var sr2 hasherSearchResult + var sr hasherSearchResult for position+hasher.HashTypeLength() < pos_end { var max_length uint = pos_end - position var max_distance uint = brotli_min_size_t(position, max_backward_limit) - var sr hasherSearchResult sr.len = 0 sr.len_code_delta = 0 sr.distance = 0 @@ -73,7 +74,6 @@ func createBackwardReferences(num_bytes uint, position uint, ringbuffer []byte, max_length-- for ; ; max_length-- { var cost_diff_lazy uint = 175 - var sr2 hasherSearchResult if params.quality < minQualityForExtensiveReferenceSearch { sr2.len = brotli_min_size_t(sr.len-1, max_length) } else { From f6e5ca97071ec527e6211127e153d5ad5a16276a Mon Sep 17 00:00:00 2001 From: Shane Hansen Date: Fri, 29 Mar 2019 15:15:07 -0700 Subject: [PATCH 2/2] gofmt --- backward_references.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backward_references.go b/backward_references.go index b22275b..1642e47 100644 --- a/backward_references.go +++ b/backward_references.go @@ -57,8 +57,8 @@ func createBackwardReferences(num_bytes uint, position uint, ringbuffer []byte, /* Minimum score to accept a backward reference. */ hasher.PrepareDistanceCache(dist_cache) - var sr2 hasherSearchResult - var sr hasherSearchResult + var sr2 hasherSearchResult + var sr hasherSearchResult for position+hasher.HashTypeLength() < pos_end { var max_length uint = pos_end - position