1
- use alloc:: { boxed:: Box , collections:: btree_map:: BTreeMap , rc:: Rc , string:: String , vec:: Vec } ;
1
+ use alloc:: {
2
+ boxed:: Box ,
3
+ collections:: { btree_map:: BTreeMap , btree_set:: BTreeSet } ,
4
+ rc:: Rc ,
5
+ string:: String ,
6
+ vec:: Vec ,
7
+ } ;
2
8
use core:: {
3
9
cell:: RefCell ,
4
10
cmp:: min,
@@ -276,7 +282,7 @@ pub struct ActiveStreamSubscription {
276
282
pub id : i64 ,
277
283
pub name : String ,
278
284
pub parameters : Option < Box < JsonString > > ,
279
- pub associated_buckets : Vec < String > ,
285
+ pub associated_buckets : BTreeSet < String > ,
280
286
pub priority : Option < BucketPriority > ,
281
287
pub active : bool ,
282
288
pub is_default : bool ,
@@ -293,7 +299,7 @@ impl ActiveStreamSubscription {
293
299
parameters : local. local_params . clone ( ) ,
294
300
is_default : local. is_default ,
295
301
priority : None ,
296
- associated_buckets : Vec :: new ( ) ,
302
+ associated_buckets : BTreeSet :: new ( ) ,
297
303
active : local. active ,
298
304
299
305
has_explicit_subscription : local. has_subscribed_manually ( ) ,
@@ -303,17 +309,8 @@ impl ActiveStreamSubscription {
303
309
}
304
310
305
311
pub fn mark_associated_with_bucket ( & mut self , bucket : & OwnedBucketChecksum ) {
306
- match self . associated_buckets . binary_search ( & bucket. bucket ) {
307
- Ok ( _) => {
308
- // The bucket is already part of the list
309
- return ;
310
- }
311
- Err ( position) => {
312
- // Insert here to keep vec sorted
313
- self . associated_buckets
314
- . insert ( position, bucket. bucket . clone ( ) ) ;
315
- }
316
- } ;
312
+ self . associated_buckets
313
+ . get_or_insert_with ( & bucket. bucket , |key| key. clone ( ) ) ;
317
314
318
315
self . priority = Some ( match self . priority {
319
316
None => bucket. priority ,
0 commit comments