Skip to content

Commit

Permalink
Lift structs to higher scope
Browse files Browse the repository at this point in the history
Small performance improvement (27%) by re-using search result
structs. Likely the original C version relied on stack allocation here.
  • Loading branch information
Shane Hansen committed Mar 29, 2019
1 parent 36f6c97 commit 94370e0
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions backward_references.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 94370e0

Please sign in to comment.