Skip to content

Commit c5d0355

Browse files
committed
proto: Change StreamsState.send to IndexMap
Adds dependency on indexmap crate, and changes StreamState.send from a HashMap to an IndexMap. Updates some usages to be idiomatic / performant. This is in preparation for a subsequent commit which will exploit useful properties of IndexMap.
1 parent 6c86fb9 commit c5d0355

File tree

4 files changed

+37
-15
lines changed

4 files changed

+37
-15
lines changed

Cargo.lock

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ futures-io = "0.3.19"
2828
getrandom = { version = "0.3", default-features = false }
2929
hdrhistogram = { version = "7.2", default-features = false }
3030
hex-literal = "0.4"
31+
indexmap = "2.9.0"
3132
lru-slab = "0.1.2"
3233
lazy_static = "1"
3334
log = "0.4"

quinn-proto/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ arbitrary = { workspace = true, optional = true }
3939
aws-lc-rs = { workspace = true, optional = true }
4040
bytes = { workspace = true }
4141
fastbloom = { workspace = true, optional = true }
42+
indexmap = { workspace = true }
4243
lru-slab = { workspace = true }
4344
rustc-hash = { workspace = true }
4445
rand = { workspace = true }

quinn-proto/src/connection/streams/state.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
use std::{
2-
collections::{VecDeque, hash_map},
3-
convert::TryFrom,
4-
mem,
5-
};
1+
use std::{collections::VecDeque, convert::TryFrom, mem};
62

73
use bytes::BufMut;
8-
use rustc_hash::FxHashMap;
4+
use indexmap::IndexMap;
5+
use rustc_hash::{FxBuildHasher, FxHashMap};
96
use tracing::{debug, trace};
107

118
use super::{
@@ -69,7 +66,7 @@ impl StreamRecv {
6966
pub 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

Comments
 (0)