From 8f0b076f65b07f856fd31693c80ac6a77f2a2fe0 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Tue, 22 Oct 2013 18:02:52 +1100 Subject: [PATCH] Set pieceByBytesPendingSlice capacity in advance to reduce memory pressure --- client.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 4a7ee817..9dcd3eee 100644 --- 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)) -- 2.48.1