From b70f91f90afd9d5df9b4b64a42e0f8513b231453 Mon Sep 17 00:00:00 2001 From: Toshit Chawda Date: Sat, 31 Aug 2024 16:29:44 -0700 Subject: [PATCH] use identity hash function --- Cargo.lock | 7 +++++++ wisp/Cargo.toml | 1 + wisp/src/inner.rs | 9 +++++---- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d38abf5..349cede 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1144,6 +1144,12 @@ dependencies = [ "getrandom", ] +[[package]] +name = "nohash-hasher" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" + [[package]] name = "nom" version = "7.1.3" @@ -2258,6 +2264,7 @@ dependencies = [ "flume", "futures", "futures-timer", + "nohash-hasher", "pin-project-lite", "tokio", ] diff --git a/wisp/Cargo.toml b/wisp/Cargo.toml index dbea286..f996abb 100644 --- a/wisp/Cargo.toml +++ b/wisp/Cargo.toml @@ -17,6 +17,7 @@ fastwebsockets = { version = "0.8.0", features = ["unstable-split"], optional = flume = "0.11.0" futures = "0.3.30" futures-timer = "3.0.3" +nohash-hasher = "0.2.0" pin-project-lite = "0.2.14" tokio = { version = "1.39.3", optional = true, default-features = false } diff --git a/wisp/src/inner.rs b/wisp/src/inner.rs index 55219f2..70a2f97 100644 --- a/wisp/src/inner.rs +++ b/wisp/src/inner.rs @@ -1,17 +1,18 @@ use std::{ - collections::HashMap, sync::{ atomic::{AtomicBool, AtomicU32, Ordering}, Arc, }, }; + use crate::{ extensions::AnyProtocolExtension, ws::{Frame, LockedWebSocketWrite, OpCode, Payload, WebSocketRead}, AtomicCloseReason, ClosePacket, CloseReason, ConnectPacket, MuxStream, Packet, PacketType, Role, StreamType, WispError, }; +use nohash_hasher::IntMap; use bytes::{Bytes, BytesMut}; use event_listener::Event; use flume as mpsc; @@ -51,7 +52,7 @@ pub struct MuxInner { fut_tx: mpsc::Sender, fut_exited: Arc, - stream_map: HashMap, + stream_map: IntMap, buffer_size: u32, target_buffer_size: u32, @@ -91,7 +92,7 @@ impl MuxInner { role: Role::Server, - stream_map: HashMap::new(), + stream_map: IntMap::default(), server_tx, }, @@ -127,7 +128,7 @@ impl MuxInner { role: Role::Client, - stream_map: HashMap::new(), + stream_map: IntMap::default(), server_tx, },