Skip to content

Commit 60cb6f2

Browse files
committed
HashMap and HashSet are now using FxHasher`
1 parent 9fe2f73 commit 60cb6f2

File tree

16 files changed

+55
-42
lines changed

16 files changed

+55
-42
lines changed

Cargo.lock

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ log = { version = "0.4", default-features = false }
3636
qlog = { version = "0.13", default-features = false }
3737
quinn-udp = { version = "0.5.6", default-features = false, features = ["direct-log", "fast-apple-datapath"] }
3838
regex = { version = "1.9", default-features = false, features = ["unicode-perl"] }
39+
rustc-hash = { version = "1.1", default-features = false, features = [ "std" ]}
3940
static_assertions = { version = "1.1", default-features = false }
4041
strum = { version = "0.26", default-features = false, features = ["derive"] }
4142
url = { version = "2.5.3", default-features = false, features = ["std"] }

neqo-bin/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ neqo-udp = { path = "./../neqo-udp" }
4040
qlog = { workspace = true }
4141
quinn-udp = { workspace = true }
4242
regex = { workspace = true }
43+
rustc-hash = { workspace = true }
4344
tokio = { version = "1", default-features = false, features = ["net", "time", "macros", "rt", "rt-multi-thread"] }
4445
url = { workspace = true }
4546

neqo-bin/src/client/http09.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88

99
//! An [HTTP 0.9](https://www.w3.org/Protocols/HTTP/AsImplemented.html) client implementation.
1010
11+
use rustc_hash::FxHashMap as HashMap;
1112
use std::{
1213
cell::RefCell,
13-
collections::{HashMap, VecDeque},
14+
collections::VecDeque,
1415
fs::File,
1516
io::{BufWriter, Write as _},
1617
net::SocketAddr,
@@ -226,7 +227,7 @@ impl super::Client for Connection {
226227
impl<'b> Handler<'b> {
227228
pub fn new(url_queue: VecDeque<Url>, args: &'b Args) -> Self {
228229
Self {
229-
streams: HashMap::new(),
230+
streams: HashMap::default(),
230231
url_queue,
231232
handled_urls: Vec::new(),
232233
all_paths: Vec::new(),

neqo-bin/src/client/http3.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88

99
//! An HTTP 3 client implementation.
1010
11+
use rustc_hash::FxHashMap as HashMap;
1112
use std::{
1213
cell::RefCell,
13-
collections::{HashMap, VecDeque},
14+
collections::VecDeque,
1415
fmt::Display,
1516
fs::File,
1617
io::{BufWriter, Write as _},
@@ -45,7 +46,7 @@ impl<'a> Handler<'a> {
4546
let url_handler = UrlHandler {
4647
url_queue,
4748
handled_urls: Vec::new(),
48-
stream_handlers: HashMap::new(),
49+
stream_handlers: HashMap::default(),
4950
all_paths: Vec::new(),
5051
args,
5152
};

neqo-bin/src/client/mod.rs

+19-16
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,6 @@
77
#![allow(clippy::future_not_send)]
88
#![allow(clippy::unwrap_used)] // This is example code.
99

10-
use std::{
11-
collections::{HashMap, VecDeque},
12-
fmt::{self, Display},
13-
fs::{create_dir_all, File, OpenOptions},
14-
io::{self, BufWriter},
15-
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, ToSocketAddrs as _},
16-
path::PathBuf,
17-
pin::Pin,
18-
process::exit,
19-
time::Instant,
20-
};
21-
2210
use clap::Parser;
2311
use futures::{
2412
future::{select, Either},
@@ -32,6 +20,18 @@ use neqo_crypto::{
3220
use neqo_http3::Output;
3321
use neqo_transport::{AppError, CloseReason, ConnectionId, Version};
3422
use neqo_udp::RecvBuf;
23+
use rustc_hash::FxHashMap as HashMap;
24+
use std::{
25+
collections::VecDeque,
26+
fmt::{self, Display},
27+
fs::{create_dir_all, File, OpenOptions},
28+
io::{self, BufWriter},
29+
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, ToSocketAddrs as _},
30+
path::PathBuf,
31+
pin::Pin,
32+
process::exit,
33+
time::Instant,
34+
};
3535
use tokio::time::Sleep;
3636
use url::{Host, Origin, Url};
3737

@@ -529,10 +529,13 @@ const fn local_addr_for(remote_addr: &SocketAddr, local_port: u16) -> SocketAddr
529529

530530
fn urls_by_origin(urls: &[Url]) -> impl Iterator<Item = ((Host, u16), VecDeque<Url>)> {
531531
urls.iter()
532-
.fold(HashMap::<Origin, VecDeque<Url>>::new(), |mut urls, url| {
533-
urls.entry(url.origin()).or_default().push_back(url.clone());
534-
urls
535-
})
532+
.fold(
533+
HashMap::<Origin, VecDeque<Url>>::default(),
534+
|mut urls, url| {
535+
urls.entry(url.origin()).or_default().push_back(url.clone());
536+
urls
537+
},
538+
)
536539
.into_iter()
537540
.filter_map(|(origin, urls)| match origin {
538541
Origin::Tuple(_scheme, h, p) => Some(((h, p), urls)),

neqo-bin/src/server/http09.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
#![allow(clippy::unwrap_used)] // This is example code.
88

9-
use std::{borrow::Cow, cell::RefCell, collections::HashMap, fmt::Display, rc::Rc, time::Instant};
9+
use rustc_hash::FxHashMap as HashMap;
10+
use std::{borrow::Cow, cell::RefCell, fmt::Display, rc::Rc, time::Instant};
1011

1112
use neqo_common::{event::Provider as _, hex, qdebug, qerror, qinfo, qwarn, Datagram};
1213
use neqo_crypto::{generate_ech_keys, random, AllowZeroRtt, AntiReplay};
@@ -68,8 +69,8 @@ impl HttpServer {
6869
let is_qns_test = args.shared.qns_test.is_some();
6970
Ok(Self {
7071
server,
71-
write_state: HashMap::new(),
72-
read_state: HashMap::new(),
72+
write_state: HashMap::default(),
73+
read_state: HashMap::default(),
7374
is_qns_test,
7475
regex: if is_qns_test {
7576
Regex::new(r"GET +/(\S+)(?:\r)?\n").map_err(|_| Error::Internal)?

neqo-bin/src/server/http3.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
#![allow(clippy::unwrap_used)] // This is example code.
88

9+
use rustc_hash::FxHashMap as HashMap;
910
use std::{
1011
cell::RefCell,
11-
collections::HashMap,
1212
fmt::{self, Display},
1313
rc::Rc,
1414
time::Instant,
@@ -68,8 +68,8 @@ impl HttpServer {
6868
}
6969
Self {
7070
server,
71-
remaining_data: HashMap::new(),
72-
posts: HashMap::new(),
71+
remaining_data: HashMap::default(),
72+
posts: HashMap::default(),
7373
is_qns_test: args.shared.qns_test.is_some(),
7474
}
7575
}

neqo-http3/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ neqo-crypto = { path = "./../neqo-crypto" }
2424
neqo-qpack = { path = "./../neqo-qpack" }
2525
neqo-transport = { path = "./../neqo-transport" }
2626
qlog = { workspace = true }
27+
rustc-hash = { workspace = true}
2728
sfv = { version = "0.9", default-features = false }
2829
url = { workspace = true }
2930

neqo-http3/src/connection.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@
44
// option. This file may not be copied, modified, or distributed
55
// except according to those terms.
66

7-
use std::{
8-
cell::RefCell,
9-
collections::{BTreeSet, HashMap},
10-
fmt::Debug,
11-
mem,
12-
rc::Rc,
13-
};
7+
use rustc_hash::FxHashMap as HashMap;
8+
use std::{cell::RefCell, collections::BTreeSet, fmt::Debug, mem, rc::Rc};
149

1510
use neqo_common::{qdebug, qerror, qinfo, qtrace, qwarn, Decoder, Header, MessageType, Role};
1611
use neqo_qpack::{decoder::QPackDecoder, encoder::QPackEncoder};
@@ -335,8 +330,8 @@ impl Http3Connection {
335330
local_params: conn_params,
336331
settings_state: Http3RemoteSettingsState::NotReceived,
337332
streams_with_pending_data: BTreeSet::new(),
338-
send_streams: HashMap::new(),
339-
recv_streams: HashMap::new(),
333+
send_streams: HashMap::default(),
334+
recv_streams: HashMap::default(),
340335
role,
341336
}
342337
}

neqo-http3/src/control_stream_local.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
// option. This file may not be copied, modified, or distributed
55
// except according to those terms.
66

7-
use std::collections::{HashMap, VecDeque};
7+
use rustc_hash::FxHashMap as HashMap;
8+
use std::collections::VecDeque;
89

910
use neqo_common::{qtrace, Encoder};
1011
use neqo_transport::{Connection, StreamId, StreamType};

neqo-http3/src/server.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
// option. This file may not be copied, modified, or distributed
55
// except according to those terms.
66

7+
use rustc_hash::FxHashMap as HashMap;
78
use std::{
89
cell::{RefCell, RefMut},
9-
collections::HashMap,
1010
path::PathBuf,
1111
rc::Rc,
1212
time::Instant,
@@ -74,7 +74,7 @@ impl Http3Server {
7474
http3_parameters.get_connection_parameters().clone(),
7575
)?,
7676
http3_parameters,
77-
http3_handlers: HashMap::new(),
77+
http3_handlers: HashMap::default(),
7878
events: Http3ServerEvents::default(),
7979
})
8080
}

neqo-qpack/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ log = { workspace = true }
2121
neqo-common = { path = "./../neqo-common" }
2222
neqo-transport = { path = "./../neqo-transport" }
2323
qlog = { workspace = true }
24+
rustc-hash = { workspace = true }
2425
static_assertions = { workspace = true }
2526

2627
[dev-dependencies]

neqo-qpack/src/encoder.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
// option. This file may not be copied, modified, or distributed
55
// except according to those terms.
66

7-
use std::collections::{HashMap, HashSet, VecDeque};
7+
use rustc_hash::FxHashMap as HashMap;
8+
use rustc_hash::FxHashSet as HashSet;
9+
use std::collections::VecDeque;
810

911
use neqo_common::{qdebug, qerror, qlog::NeqoQlog, qtrace, Header};
1012
use neqo_transport::{Connection, Error as TransportError, StreamId};
@@ -68,7 +70,7 @@ impl QPackEncoder {
6870
instruction_reader: DecoderInstructionReader::new(),
6971
local_stream: LocalStreamState::NoStream,
7072
max_blocked_streams: 0,
71-
unacked_header_blocks: HashMap::new(),
73+
unacked_header_blocks: HashMap::default(),
7274
blocked_stream_cnt: 0,
7375
use_huffman,
7476
next_capacity: None,
@@ -386,7 +388,7 @@ impl QPackEncoder {
386388
let stream_is_blocker = self.is_stream_blocker(stream_id);
387389
let can_block = self.blocked_stream_cnt < self.max_blocked_streams || stream_is_blocker;
388390

389-
let mut ref_entries = HashSet::new();
391+
let mut ref_entries = HashSet::default();
390392

391393
for iter in h {
392394
let name = iter.name().as_bytes().to_vec();

neqo-transport/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ neqo-common = { path = "../neqo-common" }
2525
neqo-crypto = { path = "../neqo-crypto" }
2626
mtu = { version = "0.2.3", default-features = false } # neqo is only user currently, can bump freely
2727
qlog = { workspace = true }
28+
rustc-hash = { workspace = true }
2829
smallvec = { version = "1.13", default-features = false }
2930
static_assertions = { workspace = true }
3031
strum = { workspace = true }

neqo-transport/src/server.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
// This file implements a server that can handle multiple connections.
88

9+
use rustc_hash::FxHashSet as HashSet;
910
use std::{
1011
cell::RefCell,
1112
cmp::min,
12-
collections::HashSet,
1313
ops::{Deref, DerefMut},
1414
path::PathBuf,
1515
rc::Rc,

0 commit comments

Comments
 (0)