Skip to content

Instantly share code, notes, and snippets.

@andrew-aladev
Created December 27, 2013 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrew-aladev/8151872 to your computer and use it in GitHub Desktop.
Save andrew-aladev/8151872 to your computer and use it in GitHub Desktop.
--- 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