]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Set pieceByBytesPendingSlice capacity in advance to reduce memory pressure
authorMatt Joiner <anacrolix@gmail.com>
Tue, 22 Oct 2013 07:02:52 +0000 (18:02 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 22 Oct 2013 07:02:52 +0000 (18:02 +1100)
client.go

index 4a7ee817dde8cbdeeb0b21ef17323345ad278891..9dcd3eeed2f62c6bf7732c46a48ff0c5fd590514 100644 (file)
--- a/client.go
+++ b/client.go
@@ -250,7 +250,10 @@ func (me pieceByBytesPendingSlice) Swap(i, j int) {
 }
 
 func (t *Torrent) piecesByPendingBytesDesc() (indices []peer_protocol.Integer) {
-       slice := pieceByBytesPendingSlice{}
+       slice := pieceByBytesPendingSlice{
+               Pending: make([]peer_protocol.Integer, 0, len(t.Pieces)),
+               Indices: make([]peer_protocol.Integer, 0, len(t.Pieces)),
+       }
        for i := range t.Pieces {
                slice.Pending = append(slice.Pending, t.PieceNumPendingBytes(peer_protocol.Integer(i)))
                slice.Indices = append(slice.Indices, peer_protocol.Integer(i))