]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Avoid allocations in shuffledPendingChunkSpecs
authorMatt Joiner <anacrolix@gmail.com>
Fri, 22 Aug 2014 07:37:18 +0000 (17:37 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Fri, 22 Aug 2014 07:37:18 +0000 (17:37 +1000)
misc.go

diff --git a/misc.go b/misc.go
index 784ecf4d8a018a30f742ecf830ce14081f3a88ea..26bf79162359b564f46c371a6930c439e6fe0f7f 100644 (file)
--- 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]