Make Definitions::find_node_for_hir_id() a linear search instead of a binary one.

Unfortunately, the NodeId->HirId array is not sorted. Since this search is only
done right before calling bug!(), let's not waste time allocating a faster lookup.
This commit is contained in:
Michael Woerister 2017-08-07 17:41:02 +02:00
parent 454533f5d9
commit 55e04d9c17

View file

@ -466,7 +466,11 @@ impl Definitions {
}
pub fn find_node_for_hir_id(&self, hir_id: hir::HirId) -> ast::NodeId {
self.node_to_hir_id.binary_search(&hir_id).unwrap()
self.node_to_hir_id
.iter()
.position(|x| *x == hir_id)
.map(|idx| ast::NodeId::new(idx))
.unwrap()
}
/// Add a definition with a parent definition.