Avoid allocations in shuffledPendingChunkSpecs
This commit is contained in:
parent
189f1e364e
commit
063e02cbfd
6
misc.go
6
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]
|
||||
|
|
Loading…
Reference in New Issue