Avoid allocating a slice when iterating pending chunks
This commit is contained in:
parent
2e3281421f
commit
f1e4840959
|
@ -797,10 +797,13 @@ func iterUndirtiedChunks(piece pieceIndex, t *Torrent, f func(chunkSpec) bool) b
|
|||
}
|
||||
return true
|
||||
}
|
||||
chunkIndices := t.pieces[piece].undirtiedChunkIndices().ToSortedSlice()
|
||||
// TODO: Use "math/rand".Shuffle >= Go 1.10
|
||||
return iter.ForPerm(len(chunkIndices), func(i int) bool {
|
||||
return f(t.chunkIndexSpec(pp.Integer(chunkIndices[i]), piece))
|
||||
chunkIndices := t.pieces[piece].undirtiedChunkIndices()
|
||||
return iter.ForPerm(chunkIndices.Len(), func(i int) bool {
|
||||
ci, err := chunkIndices.RB.Select(uint32(i))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return f(t.chunkIndexSpec(pp.Integer(ci), piece))
|
||||
})
|
||||
}
|
||||
|
||||
|
|
8
go.mod
8
go.mod
|
@ -6,7 +6,7 @@ require (
|
|||
github.com/anacrolix/envpprof v0.0.0-20180404065416-323002cec2fa
|
||||
github.com/anacrolix/go-libutp v0.0.0-20180808010927-aebbeb60ea05
|
||||
github.com/anacrolix/log v0.2.0
|
||||
github.com/anacrolix/missinggo v0.0.0-20181129073415-3237bf955fed
|
||||
github.com/anacrolix/missinggo v0.1.1-0.20190216073122-118c32fc17c8
|
||||
github.com/anacrolix/sync v0.0.0-20180808010631-44578de4e778
|
||||
github.com/anacrolix/tagflag v0.0.0-20180803105420-3a8ff5428f76
|
||||
github.com/anacrolix/utp v0.0.0-20180219060659-9e0e1d1d0572
|
||||
|
@ -17,21 +17,15 @@ require (
|
|||
github.com/edsrzf/mmap-go v1.0.0
|
||||
github.com/elgatito/upnp v0.0.0-20180711183757-2f244d205f9a
|
||||
github.com/fsnotify/fsnotify v1.4.7
|
||||
github.com/glycerine/goconvey v0.0.0-20180728074245-46e3a41ad493 // indirect
|
||||
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e // indirect
|
||||
github.com/gosuri/uiprogress v0.0.0-20170224063937-d0567a9d84a1
|
||||
github.com/jessevdk/go-flags v1.4.0
|
||||
github.com/jtolds/gls v4.2.1+incompatible // indirect
|
||||
github.com/mattn/go-isatty v0.0.4 // indirect
|
||||
github.com/mattn/go-sqlite3 v1.10.0
|
||||
github.com/mschoch/smat v0.0.0-20160514031455-90eadee771ae // indirect
|
||||
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7 // indirect
|
||||
github.com/pkg/errors v0.8.0
|
||||
github.com/smartystreets/assertions v0.0.0-20190215210624-980c5ac6f3ac // indirect
|
||||
github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c // indirect
|
||||
github.com/stretchr/testify v1.2.2
|
||||
github.com/willf/bitset v1.1.9 // indirect
|
||||
golang.org/x/net v0.0.0-20181220203305-927f97764cc3
|
||||
golang.org/x/sys v0.0.0-20190102155601-82a175fd1598 // indirect
|
||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c
|
||||
|
|
3
go.sum
3
go.sum
|
@ -19,6 +19,8 @@ github.com/anacrolix/missinggo v0.0.0-20180522035225-b4a5853e62ff/go.mod h1:b0p+
|
|||
github.com/anacrolix/missinggo v0.0.0-20180725070939-60ef2fbf63df/go.mod h1:kwGiTUTZ0+p4vAz3VbAI5a30t2YbvemcmspjKwrAz5s=
|
||||
github.com/anacrolix/missinggo v0.0.0-20181129073415-3237bf955fed h1:pMzstxgUXooGmNxZnjFSsnjtFd7s81sNI7L2pzEuWWs=
|
||||
github.com/anacrolix/missinggo v0.0.0-20181129073415-3237bf955fed/go.mod h1:IN+9GUe7OxKMIs/XeXEbT/rMUolmJzmlZiXHS7FwD/Y=
|
||||
github.com/anacrolix/missinggo v0.1.1-0.20190216073122-118c32fc17c8 h1:TLXmcvtwt3ldszBQ5fzaxpsbB7CuB07BhYulGoPkMpM=
|
||||
github.com/anacrolix/missinggo v0.1.1-0.20190216073122-118c32fc17c8/go.mod h1:MBJu3Sk/k3ZfGYcS7z18gwfu72Ey/xopPFJJbTi5yIo=
|
||||
github.com/anacrolix/mmsg v0.0.0-20180515031531-a4a3ba1fc8bb h1:2Or5ccMoY4Kfao+WdL2w6tpY6ZEe+2VTVbIPd7A/Ajk=
|
||||
github.com/anacrolix/mmsg v0.0.0-20180515031531-a4a3ba1fc8bb/go.mod h1:x2/ErsYUmT77kezS63+wzZp8E3byYB0gzirM/WMBLfw=
|
||||
github.com/anacrolix/sync v0.0.0-20171108081538-eee974e4f8c1/go.mod h1:+u91KiUuf0lyILI6x3n/XrW7iFROCZCG+TjgK8nW52w=
|
||||
|
@ -96,6 +98,7 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
|||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/ryszard/goskiplist v0.0.0-20150312221310-2dfbae5fcf46 h1:GHRpF1pTW19a8tTFrMLUcfWwyC0pnifVo2ClaLq+hP8=
|
||||
github.com/ryszard/goskiplist v0.0.0-20150312221310-2dfbae5fcf46/go.mod h1:uAQ5PCi+MFsC7HjREoAz1BU+Mq60+05gifQSsHSDG/8=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||
github.com/smartystreets/assertions v0.0.0-20190215210624-980c5ac6f3ac h1:wbW+Bybf9pXxnCFAOWZTqkRjAc7rAIwo2e1ArUhiHxg=
|
||||
github.com/smartystreets/assertions v0.0.0-20190215210624-980c5ac6f3ac/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||
github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c h1:Ho+uVpkel/udgjbwB5Lktg9BtvJSh2DT0Hi6LPSyI2w=
|
||||
|
|
Loading…
Reference in New Issue