]> git.lizzy.rs Git - rust.git/commitdiff
Make Definitions::find_node_for_hir_id() a linear search instead of a binary one.
authorMichael Woerister <michaelwoerister@posteo>
Mon, 7 Aug 2017 15:41:02 +0000 (17:41 +0200)
committerMichael Woerister <michaelwoerister@posteo>
Fri, 11 Aug 2017 10:11:38 +0000 (12:11 +0200)
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

index d3e3998360b602c114be14ae0b171769f9001e04..67a4d71d90c1cf28d17f4b2136870e19dc4b2c71 100644 (file)
@@ -466,7 +466,11 @@ pub fn node_to_hir_id(&self, node_id: ast::NodeId) -> hir::HirId {
     }
 
     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.