From 55e04d9c17c655bdb6d1e6f7256d398482bf1599 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Mon, 7 Aug 2017 17:41:02 +0200 Subject: [PATCH] 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. --- src/librustc/hir/map/definitions.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/librustc/hir/map/definitions.rs b/src/librustc/hir/map/definitions.rs index d3e3998360b6..67a4d71d90c1 100644 --- a/src/librustc/hir/map/definitions.rs +++ b/src/librustc/hir/map/definitions.rs @@ -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.