about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Woerister <michaelwoerister@posteo>2017-08-07 17:41:02 +0200
committerMichael Woerister <michaelwoerister@posteo>2017-08-11 12:11:38 +0200
commit55e04d9c17c655bdb6d1e6f7256d398482bf1599 (patch)
tree32e222092cb49e3bff246e003dcf8652f26a2a30
parent454533f5d93421eb2532fc6ee0fcd3007142cff6 (diff)
downloadrust-55e04d9c17c655bdb6d1e6f7256d398482bf1599.tar.gz
rust-55e04d9c17c655bdb6d1e6f7256d398482bf1599.zip
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.
-rw-r--r--src/librustc/hir/map/definitions.rs6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/librustc/hir/map/definitions.rs b/src/librustc/hir/map/definitions.rs
index d3e3998360b..67a4d71d90c 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.