Author: alanmc
Date: 2007-03-31 11:34:16 -0500 (Sat, 31 Mar 2007)
New Revision: 75241
Modified:
trunk/bitsharp/src/MonoTorrent.Client/BitField.cs
trunk/bitsharp/src/MonoTorrent.Client/PiecePicking/StandardPicker.cs
Log:
Updated StandardPiecePicker.PickPiece() to use faster methods of getting a
piece.
Modified: trunk/bitsharp/src/MonoTorrent.Client/BitField.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent.Client/BitField.cs 2007-03-31 16:33:33 UTC
(rev 75240)
+++ trunk/bitsharp/src/MonoTorrent.Client/BitField.cs 2007-03-31 16:34:16 UTC
(rev 75241)
@@ -124,7 +124,7 @@
for (int i = 0; i < this.array.Length; i++)
this.array[i] = ~this.array[i];
- UpdateTrueCount();
+ this.trueCount = this.length - this.trueCount;
return this;
}
@@ -136,20 +136,26 @@
/// <returns>Itself</returns>
internal BitField And(BitField value)
{
- if (value == null)
- throw new ArgumentNullException("value");
+ AndFast(value);
+ UpdateTrueCount();
+ return this;
+ }
- if (this.length != value.length)
- throw new ArgumentException("BitFields are of different
lengths", "value");
- for (int i = 0; i < this.array.Length; i++)
- this.array[i] &= value.array[i];
+ internal BitField AndFast(BitField value)
+ {
+ if (value == null)
+ throw new ArgumentNullException("value");
- UpdateTrueCount();
- return this;
- }
+ if (this.length != value.length)
+ throw new ArgumentException("BitFields are of
different lengths", "value");
+ for (int i = 0; i < this.array.Length; i++)
+ this.array[i] &= value.array[i];
+ return this;
+ }
+
/// <summary>
/// Performs binary NAND on all the elements of this bitarray against
the elements of the supplied BitField
/// </summary>
@@ -319,6 +325,16 @@
}
+ internal bool AllFalseSecure()
+ {
+ for (int i = 0; i < this.array.Length; i++)
+ if (this.array[i] != 0)
+ return false;
+
+ return true;
+ }
+
+
/// <summary>
/// Returns true if all the elements in the bitfield are true
/// </summary>
Modified: trunk/bitsharp/src/MonoTorrent.Client/PiecePicking/StandardPicker.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent.Client/PiecePicking/StandardPicker.cs
2007-03-31 16:33:33 UTC (rev 75240)
+++ trunk/bitsharp/src/MonoTorrent.Client/PiecePicking/StandardPicker.cs
2007-03-31 16:34:16 UTC (rev 75241)
@@ -327,7 +327,7 @@
// Now we see what pieces the peer has that we don't have and
try and request one
Buffer.BlockCopy(this.myBitfield.Array, 0,
bufferBitfield.Array, 0, this.bufferBitfield.Array.Length * 4);
this.bufferBitfield.Not();
- this.bufferBitfield.And(id.Peer.Connection.BitField);
+ this.bufferBitfield.AndFast(id.Peer.Connection.BitField);
// Out of the pieces the other peer has that we want, we look
for the highest priority and store it here.
// We then keep NANDing the bitfield until we no longer have
pieces with that priority. Then we can pick
@@ -346,8 +346,8 @@
continue;
Buffer.BlockCopy(this.bufferBitfield.Array, 0,
this.previousBitfield.Array, 0, this.bufferBitfield.Array.Length * 4);
-
this.bufferBitfield.And(otherPeers[i].Peer.Connection.BitField);
- if (this.bufferBitfield.AllFalse ||
highestPriorityFound != HighestPriorityAvailable(this.bufferBitfield))
+
this.bufferBitfield.AndFast(otherPeers[i].Peer.Connection.BitField);
+ if (this.bufferBitfield.AllFalseSecure() ||
highestPriorityFound != HighestPriorityAvailable(this.bufferBitfield))
break;
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches