From: Matt Joiner Date: Fri, 22 Aug 2014 07:37:18 +0000 (+1000) Subject: Avoid allocations in shuffledPendingChunkSpecs X-Git-Tag: v1.0.0~1618 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=063e02cbfd2ecaf5ac732180676214353761c0e1;p=btrtrc.git Avoid allocations in shuffledPendingChunkSpecs --- diff --git a/misc.go b/misc.go index 784ecf4d..26bf7916 100644 --- a/misc.go +++ b/misc.go @@ -36,10 +36,16 @@ type piece struct { } func (p *piece) shuffledPendingChunkSpecs() (css []chunkSpec) { + if len(p.PendingChunkSpecs) == 0 { + return + } css = make([]chunkSpec, 0, len(p.PendingChunkSpecs)) for cs := range p.PendingChunkSpecs { css = append(css, cs) } + if len(css) <= 1 { + return + } for i := range css { j := rand.Intn(i + 1) css[i], css[j] = css[j], css[i]