if (b->parent)
{
- void * removed;
-
assert (tr_isBandwidth (b->parent));
-
- removed = tr_ptrArrayRemoveSorted (&b->parent->children, b, compareBandwidth);
- assert (removed == b);
- assert (tr_ptrArrayFindSorted (&b->parent->children, b, compareBandwidth) == NULL);
-
+ tr_ptrArrayRemoveSortedPointer (&b->parent->children, b, compareBandwidth);
b->parent = NULL;
}
const tr_address * addr;
tr_peerMgr * manager = vmanager;
tr_swarm * s;
- tr_handshake * ours;
assert (io);
assert (tr_isBool (ok));
: NULL;
if (tr_peerIoIsIncoming (io))
- ours = tr_ptrArrayRemoveSorted (&manager->incomingHandshakes,
+ tr_ptrArrayRemoveSortedPointer (&manager->incomingHandshakes,
handshake, handshakeCompare);
else if (s)
- ours = tr_ptrArrayRemoveSorted (&s->outgoingHandshakes,
+ tr_ptrArrayRemoveSortedPointer (&s->outgoingHandshakes,
handshake, handshakeCompare);
- else
- ours = handshake;
-
- assert (ours);
- assert (ours == handshake);
if (s)
swarmLock (s);
static void
removePeer (tr_swarm * s, tr_peer * peer)
{
- tr_peer * removed;
struct peer_atom * atom = peer->atom;
assert (swarmIsLocked (s));
atom->time = tr_time ();
- removed = tr_ptrArrayRemoveSorted (&s->peers, peer, peerCompare);
+ tr_ptrArrayRemoveSortedPointer (&s->peers, peer, peerCompare);
--s->stats.peerCount;
--s->stats.peerFromCount[atom->fromFirst];
if (replicationExists (s))
tr_decrReplicationFromBitfield (s, &peer->have);
- assert (removed == peer);
assert (s->stats.peerCount == tr_ptrArraySize (&s->peers));
assert (s->stats.peerFromCount[atom->fromFirst] >= 0);
- tr_peerFree (removed);
+ tr_peerFree (peer);
}
static void
return match ? t->items[pos] : NULL;
}
-void*
-tr_ptrArrayRemoveSorted (tr_ptrArray * t,
- const void * ptr,
- int compare (const void*, const void*))
+static void*
+tr_ptrArrayRemoveSortedValue (tr_ptrArray * t,
+ const void * ptr,
+ int compare (const void*, const void*))
{
int pos;
bool match;
assert ((ret == NULL) || (compare (ret, ptr) == 0));
return ret;
}
+
+void
+tr_ptrArrayRemoveSortedPointer (tr_ptrArray * t,
+ const void * ptr,
+ int compare (const void*, const void*))
+{
+#ifdef NDEBUG
+ tr_ptrArrayRemoveSortedValue (t, ptr, compare);
+#else
+ void * removed = tr_ptrArrayRemoveSortedValue (t, ptr, compare);
+ assert (removed != NULL);
+ assert (removed == ptr);
+ assert (tr_ptrArrayFindSorted (t, ptr, compare) == NULL);
+#endif
+}
void * value,
int compare (const void*, const void*));
-/** @brief Remove a pointer from an array sorted by the specified sort function
- @return the matching pointer, or NULL if no match was found */
-void* tr_ptrArrayRemoveSorted (tr_ptrArray * array,
- const void * value,
- int compare (const void*, const void*));
+/** @brief Remove this specific pointer from a sorted ptrarray */
+void tr_ptrArrayRemoveSortedPointer (tr_ptrArray * t,
+ const void * ptr,
+ int compare (const void*, const void*));
+
/** @brief Find a pointer from an array sorted by the specified sort function
@return the matching pointer, or NULL if no match was found */