This commit is contained in:
J.Teeuwissen 2022-12-22 15:42:26 +01:00
parent 5229edd742
commit 1caafbc131
No known key found for this signature in database
GPG key ID: DB5F7A1ED8D478AD

View file

@ -117,8 +117,10 @@ struct Declaration<'a> {
impl<'a> Hash for Declaration<'a> { impl<'a> Hash for Declaration<'a> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) { fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.symbol.hash(state); self.symbol.hash(state);
// Only hash ths symbol, as it's faster and is almost always unique. // Declaration is used as a key in DeclarationToIndex.
// If not unique, a slower equality comparison with the layout can be used. // Only the symbol is hashed, as calculating the hash for the layout is slow.
// If the symbol is not unique (it collides with another symbol with a different value),
// a slower equality comparison will still include the layout.
} }
} }
@ -160,15 +162,9 @@ impl<'a> DeclarationToIndex<'a> {
let similar = self let similar = self
.elements .elements
.iter() .iter()
.filter_map( .filter_map(|(Declaration { symbol, layout }, _)| {
|( (*symbol == needle_symbol).then_some(layout)
Declaration { })
symbol: s,
layout: lay,
},
_,
)| if *s == needle_symbol { Some(lay) } else { None },
)
.collect::<std::vec::Vec<_>>(); .collect::<std::vec::Vec<_>>();
unreachable!( unreachable!(
"symbol/layout {:?} {:#?} combo must be in DeclarationToIndex\nHowever {} similar layouts were found:\n{:#?}", "symbol/layout {:?} {:#?} combo must be in DeclarationToIndex\nHowever {} similar layouts were found:\n{:#?}",