diff options
author | erdgeist <> | 2008-11-03 01:28:10 +0000 |
---|---|---|
committer | erdgeist <> | 2008-11-03 01:28:10 +0000 |
commit | 3f5468672bce33ee86017b5e9cd5d9407b5d95ab (patch) | |
tree | 6fd33f4c106435c762456031614f2811cfecea28 | |
parent | 933f8d9b52fbfb013674be97af1c46e01f5bd0be (diff) |
Never let vectors shrink below their minimal capacity
-rw-r--r-- | ot_vector.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/ot_vector.c b/ot_vector.c index 0e65d09..2dcbb08 100644 --- a/ot_vector.c +++ b/ot_vector.c | |||
@@ -125,7 +125,7 @@ int vector_remove_peer( ot_vector *vector, ot_peer *peer, int hysteresis ) { | |||
125 | if( !exactmatch ) return 0; | 125 | if( !exactmatch ) return 0; |
126 | exactmatch = ( OT_FLAG( match ) & PEER_FLAG_SEEDING ) ? 2 : 1; | 126 | exactmatch = ( OT_FLAG( match ) & PEER_FLAG_SEEDING ) ? 2 : 1; |
127 | memmove( match, match + 1, sizeof(ot_peer) * ( end - match - 1 ) ); | 127 | memmove( match, match + 1, sizeof(ot_peer) * ( end - match - 1 ) ); |
128 | if( ( --vector->size * shrink_thresh < vector->space ) && ( vector->space > OT_VECTOR_MIN_MEMBERS ) ) { | 128 | if( ( --vector->size * shrink_thresh < vector->space ) && ( vector->space >= OT_VECTOR_SHRINK_RATIO * OT_VECTOR_MIN_MEMBERS ) ) { |
129 | vector->space /= OT_VECTOR_SHRINK_RATIO; | 129 | vector->space /= OT_VECTOR_SHRINK_RATIO; |
130 | vector->data = realloc( vector->data, vector->space * sizeof( ot_peer ) ); | 130 | vector->data = realloc( vector->data, vector->space * sizeof( ot_peer ) ); |
131 | } | 131 | } |
@@ -155,7 +155,7 @@ void vector_remove_torrent( ot_vector *vector, ot_torrent *match ) { | |||
155 | if( match->peer_list) free_peerlist( match->peer_list ); | 155 | if( match->peer_list) free_peerlist( match->peer_list ); |
156 | 156 | ||
157 | memmove( match, match + 1, sizeof(ot_torrent) * ( end - match - 1 ) ); | 157 | memmove( match, match + 1, sizeof(ot_torrent) * ( end - match - 1 ) ); |
158 | if( ( --vector->size * OT_VECTOR_SHRINK_THRESH < vector->space ) && ( vector->space > OT_VECTOR_MIN_MEMBERS ) ) { | 158 | if( ( --vector->size * OT_VECTOR_SHRINK_THRESH < vector->space ) && ( vector->space >= OT_VECTOR_SHRINK_RATIO * OT_VECTOR_MIN_MEMBERS ) ) { |
159 | vector->space /= OT_VECTOR_SHRINK_RATIO; | 159 | vector->space /= OT_VECTOR_SHRINK_RATIO; |
160 | vector->data = realloc( vector->data, vector->space * sizeof( ot_torrent ) ); | 160 | vector->data = realloc( vector->data, vector->space * sizeof( ot_torrent ) ); |
161 | } | 161 | } |