Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
--- a/libtransmission/peer-mgr.c 2013-06-30 22:58:23.208920486 +0300
+++ b/libtransmission/peer-mgr.c 2013-06-30 23:07:26.238865338 +0300
@@ -1003,6 +1003,27 @@
return 0;
}
+static int
+comparePieceForSequential ( const void * va, const void * vb )
+{
+ const struct weighted_piece * a = va;
+ const struct weighted_piece * b = vb;
+ int ia, ib;
+ const tr_torrent * tor = weightTorrent;
+
+ /* higher priorities go first */
+ ia = tor->info.pieces[a->index].priority;
+ ib = tor->info.pieces[b->index].priority;
+ if( ia > ib ) return -1;
+ if( ia < ib ) return 1;
+
+ /* sequential */
+ if( a->index < b->index ) return -1;
+ if( a->index > b->index ) return 1;
+
+ return 0;
+}
+
static void
pieceListSort (tr_swarm * s, enum piece_sort_state state)
{
@@ -1012,7 +1033,7 @@
if (state == PIECES_SORTED_BY_WEIGHT)
{
setComparePieceByWeightTorrent (s);
- qsort (s->pieces, s->pieceCount, sizeof (struct weighted_piece), comparePieceByWeight);
+ qsort (s->pieces, s->pieceCount, sizeof (struct weighted_piece), comparePieceForSequential);
}
else
{
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment