Avoid allocations in shuffledPendingChunkSpecs

This commit is contained in:
Matt Joiner 2014-08-22 17:37:18 +10:00
parent 189f1e364e
commit 063e02cbfd
1 changed files with 6 additions and 0 deletions

View File

@ -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]