1- use std:: {
2- collections:: { VecDeque , hash_map} ,
3- convert:: TryFrom ,
4- mem,
5- } ;
1+ use std:: { collections:: VecDeque , convert:: TryFrom , mem} ;
62
73use bytes:: BufMut ;
8- use rustc_hash:: FxHashMap ;
4+ use indexmap:: IndexMap ;
5+ use rustc_hash:: { FxBuildHasher , FxHashMap } ;
96use tracing:: { debug, trace} ;
107
118use super :: {
@@ -69,7 +66,7 @@ impl StreamRecv {
6966pub struct StreamsState {
7067 pub ( super ) side : Side ,
7168 // Set of streams that are currently open, or could be immediately opened by the peer
72- pub ( super ) send : FxHashMap < StreamId , Option < Box < Send > > > ,
69+ pub ( super ) send : IndexMap < StreamId , Option < Box < Send > > , FxBuildHasher > ,
7370 pub ( super ) recv : FxHashMap < StreamId , Option < StreamRecv > > ,
7471 pub ( super ) free_recv : Vec < StreamRecv > ,
7572 pub ( super ) next : [ u64 ; 2 ] ,
@@ -149,7 +146,7 @@ impl StreamsState {
149146 ) -> Self {
150147 let mut this = Self {
151148 side,
152- send : FxHashMap :: default ( ) ,
149+ send : IndexMap :: default ( ) ,
153150 recv : FxHashMap :: default ( ) ,
154151 free_recv : Vec :: new ( ) ,
155152 next : [ 0 , 0 ] ,
@@ -225,7 +222,7 @@ impl StreamsState {
225222 // We don't bother calling `stream_freed` here because we explicitly reset affected
226223 // counters below.
227224 let id = StreamId :: new ( self . side , dir, i) ;
228- self . send . remove ( & id) . unwrap ( ) ;
225+ self . send . swap_remove ( & id) . unwrap ( ) ;
229226 if let Dir :: Bi = dir {
230227 self . recv . remove ( & id) . unwrap ( ) ;
231228 }
@@ -379,10 +376,10 @@ impl StreamsState {
379376
380377 pub ( crate ) fn reset_acked ( & mut self , id : StreamId ) {
381378 match self . send . entry ( id) {
382- hash_map :: Entry :: Vacant ( _) => { }
383- hash_map :: Entry :: Occupied ( e) => {
379+ indexmap :: map :: Entry :: Vacant ( _) => { }
380+ indexmap :: map :: Entry :: Occupied ( e) => {
384381 if let Some ( SendState :: ResetSent ) = e. get ( ) . as_ref ( ) . map ( |s| s. state ) {
385- e. remove_entry ( ) ;
382+ e. swap_remove_entry ( ) ;
386383 self . stream_freed ( id, StreamHalf :: Send ) ;
387384 }
388385 }
@@ -636,8 +633,8 @@ impl StreamsState {
636633
637634 pub ( crate ) fn received_ack_of ( & mut self , frame : frame:: StreamMeta ) {
638635 let mut entry = match self . send . entry ( frame. id ) {
639- hash_map :: Entry :: Vacant ( _) => return ,
640- hash_map :: Entry :: Occupied ( e) => e,
636+ indexmap :: map :: Entry :: Vacant ( _) => return ,
637+ indexmap :: map :: Entry :: Occupied ( e) => e,
641638 } ;
642639
643640 let stream = match entry. get_mut ( ) . as_mut ( ) {
@@ -662,7 +659,7 @@ impl StreamsState {
662659 return ;
663660 }
664661
665- entry. remove_entry ( ) ;
662+ entry. swap_remove_entry ( ) ;
666663 self . stream_freed ( id, StreamHalf :: Send ) ;
667664 self . events . push_back ( StreamEvent :: Finished { id } ) ;
668665 }
0 commit comments