From 063e02cbfd2ecaf5ac732180676214353761c0e1 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Fri, 22 Aug 2014 17:37:18 +1000 Subject: [PATCH] Avoid allocations in shuffledPendingChunkSpecs --- misc.go | 6 ++++++ 1 file changed, 6 insertions(+) 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] -- 2.44.0