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+ } ;
28use core:: {
39 cell:: RefCell ,
410 cmp:: min,
@@ -276,7 +282,7 @@ pub struct ActiveStreamSubscription {
276282 pub id : i64 ,
277283 pub name : String ,
278284 pub parameters : Option < Box < JsonString > > ,
279- pub associated_buckets : Vec < String > ,
285+ pub associated_buckets : BTreeSet < String > ,
280286 pub priority : Option < BucketPriority > ,
281287 pub active : bool ,
282288 pub is_default : bool ,
@@ -293,7 +299,7 @@ impl ActiveStreamSubscription {
293299 parameters : local. local_params . clone ( ) ,
294300 is_default : local. is_default ,
295301 priority : None ,
296- associated_buckets : Vec :: new ( ) ,
302+ associated_buckets : BTreeSet :: new ( ) ,
297303 active : local. active ,
298304
299305 has_explicit_subscription : local. has_subscribed_manually ( ) ,
@@ -303,17 +309,8 @@ impl ActiveStreamSubscription {
303309 }
304310
305311 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 ( ) ) ;
317314
318315 self . priority = Some ( match self . priority {
319316 None => bucket. priority ,
0 commit comments