Skip to content

Commit

Permalink
perf: Avoid hashing symbols twice
Browse files Browse the repository at this point in the history
  • Loading branch information
Marwes committed Mar 15, 2020
1 parent af945c4 commit 0cfb52c
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions base/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,10 +613,13 @@ impl Symbols {
name_ref.hash(&mut hasher);
let hash = hasher.finish();

self.indexes
match self
.indexes
.raw_entry_mut()
.from_hash(hash, |key| *key == name_ref)
.or_insert_with(|| {
{
hashbrown::hash_map::RawEntryMut::Occupied(entry) => entry.get().clone(),
hashbrown::hash_map::RawEntryMut::Vacant(entry) => {
let SymbolData {
global,
location,
Expand All @@ -639,17 +642,20 @@ impl Symbols {
location: inner_location,
name,
}));
(
SymbolData {
global,
location,
name: key,
},
s,
)
})
.1
.clone()
entry
.insert_hashed_nocheck(
hash,
SymbolData {
global,
location,
name: key,
},
s,
)
.1
.clone()
}
}
}

pub fn contains_name<N>(&mut self, name: N) -> bool
Expand Down

0 comments on commit 0cfb52c

Please sign in to comment.