Skip to content

Commit f003311

Browse files
authored
Merge pull request #19 from bytecodealliance/fx-hashmaps
Use FxHashMap/FxHashSet rather than std HashMap everywhere.
2 parents 183042d + c0c1745 commit f003311

8 files changed

Lines changed: 18 additions & 16 deletions

File tree

src/backend/localify.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use crate::backend::treeify::Trees;
55
use crate::cfg::CFGInfo;
66
use crate::entity::{EntityVec, PerEntity};
77
use crate::ir::{Block, FunctionBody, Local, Type, Value, ValueDef};
8+
use fxhash::{FxHashMap as HashMap, FxHashSet as HashSet};
89
use smallvec::{smallvec, SmallVec};
9-
use std::collections::{HashMap, HashSet};
1010
use std::ops::Range;
1111

1212
#[derive(Clone, Debug, Default)]
@@ -242,13 +242,13 @@ impl<'a> Context<'a> {
242242
ranges.sort_unstable_by_key(|(val, range)| (range.start, *val));
243243

244244
// Keep a list of expiring Locals by expiry point.
245-
let mut expiring: HashMap<usize, SmallVec<[(Type, Local); 8]>> = HashMap::new();
245+
let mut expiring: HashMap<usize, SmallVec<[(Type, Local); 8]>> = HashMap::default();
246246

247247
// Iterate over allocation space, processing range starts (at
248248
// which point we allocate) and ends (at which point we add to
249249
// the freelist).
250250
let mut range_idx = 0;
251-
let mut freelist: HashMap<Type, Vec<Local>> = HashMap::new();
251+
let mut freelist: HashMap<Type, Vec<Local>> = HashMap::default();
252252

253253
for i in 0..self.points {
254254
// Process ends. (Ends are exclusive, so we do them

src/backend/reducify.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,11 @@
150150
151151
use crate::entity::EntityRef;
152152
use crate::{cfg::CFGInfo, cfg::RPOIndex, entity::PerEntity, Block, FunctionBody, Value, ValueDef};
153+
use fxhash::FxHashSet as HashSet;
153154
use fxhash::{FxHashMap, FxHashSet};
154155
use smallvec::SmallVec;
155156
use std::borrow::Cow;
156-
use std::collections::{HashSet, VecDeque};
157+
use std::collections::VecDeque;
157158

158159
pub struct Reducifier<'a> {
159160
body: &'a FunctionBody,

src/backend/stackify.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use crate::cfg::CFGInfo;
1313
use crate::entity::EntityRef;
1414
use crate::ir::{Block, BlockTarget, FunctionBody, Terminator, Type, Value};
15-
use std::collections::HashSet;
15+
use fxhash::FxHashSet as HashSet;
1616
use std::convert::TryFrom;
1717

1818
#[derive(Clone, Debug)]
@@ -134,9 +134,9 @@ impl<'a, 'b> Context<'a, 'b> {
134134
body: &FunctionBody,
135135
cfg: &CFGInfo,
136136
) -> anyhow::Result<(HashSet<Block>, HashSet<Block>)> {
137-
let mut loop_headers = HashSet::new();
138-
let mut branched_once = HashSet::new();
139-
let mut merge_nodes = HashSet::new();
137+
let mut loop_headers = HashSet::default();
138+
let mut branched_once = HashSet::default();
139+
let mut merge_nodes = HashSet::default();
140140

141141
for (block_rpo, &block) in cfg.rpo.entries() {
142142
for &succ in &body.blocks[block].succs {

src/interp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::ir::*;
55
use crate::ops::Operator;
66
use smallvec::{smallvec, SmallVec};
77

8-
use std::collections::HashMap;
8+
use fxhash::FxHashMap as HashMap;
99

1010
/// How large do we allow a Wasm memory to be when interpreting? Limit
1111
/// the size somewhat (apply an implementation limit) so we do not
@@ -156,7 +156,7 @@ impl InterpContext {
156156
let mut frame = InterpStackFrame {
157157
func,
158158
cur_block: body.entry,
159-
values: HashMap::new(),
159+
values: HashMap::default(),
160160
};
161161

162162
for (&arg, &(_, blockparam)) in args.iter().zip(body.blocks[body.entry].params.iter()) {

src/ir/debug.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use crate::declare_entity;
44
use crate::entity::EntityVec;
55
#[cfg(feature = "dwarf")]
66
use addr2line::gimli;
7+
use fxhash::FxHashMap as HashMap;
78
use std::collections::hash_map::Entry as HashEntry;
8-
use std::collections::HashMap;
99

1010
declare_entity!(SourceFile, "file");
1111
declare_entity!(SourceLoc, "loc");

src/ir/display.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use super::{Func, FuncDecl, FunctionBody, Module, SourceLoc, ValueDef};
44
use crate::entity::EntityRef;
5-
use std::collections::HashMap;
5+
use fxhash::FxHashMap as HashMap;
66
use std::fmt::{self, Display, Formatter, Result as FmtResult};
77

88
/// Hooks to print information after instruction, before and after blocks
@@ -253,7 +253,7 @@ impl<'a, PD: PrintDecorator> Display for ModuleDisplay<'a, PD> {
253253
if let Some(func) = self.module.start_func {
254254
writeln!(f, " start = {}", func)?;
255255
}
256-
let mut sig_strs = HashMap::new();
256+
let mut sig_strs = HashMap::default();
257257
for (sig, sig_data) in self.module.signatures.entries() {
258258
let arg_tys = sig_data
259259
.params

src/ir/func.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::pool::{ListPool, ListRef};
1212
use crate::Operator;
1313
use anyhow::Result;
1414
use fxhash::FxHashMap;
15-
use std::collections::HashSet;
15+
use fxhash::FxHashSet as HashSet;
1616

1717
/// A declaration of a function: there is one `FuncDecl` per `Func`
1818
/// index.

src/passes/maxssa.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
use crate::cfg::CFGInfo;
88
use crate::entity::PerEntity;
99
use crate::ir::{Block, FunctionBody, Value, ValueDef};
10-
use std::collections::{BTreeSet, HashMap, HashSet};
10+
use fxhash::{FxHashMap as HashMap, FxHashSet as HashSet};
11+
use std::collections::BTreeSet;
1112

1213
pub(crate) fn run(body: &mut FunctionBody, cut_blocks: Option<HashSet<Block>>, cfg: &CFGInfo) {
1314
MaxSSAPass::new(cut_blocks).run(body, cfg);
@@ -30,7 +31,7 @@ impl MaxSSAPass {
3031
Self {
3132
cut_blocks,
3233
new_args: PerEntity::default(),
33-
value_map: HashMap::new(),
34+
value_map: HashMap::default(),
3435
}
3536
}
3637

0 commit comments

Comments
 (0)