]> git.lizzy.rs Git - rust.git/commitdiff
Use `SmallVector` in `CombineFields::instantiate`.
authorNicholas Nethercote <nnethercote@mozilla.com>
Fri, 21 Oct 2016 09:22:28 +0000 (20:22 +1100)
committerNicholas Nethercote <nnethercote@mozilla.com>
Mon, 24 Oct 2016 03:08:06 +0000 (14:08 +1100)
This avoids 4% of malloc calls when compiling
rustc-benchmarks/issue-32278-big-array-of-strings, and 1--2% for other
benchmarks. A small win, but an easy one.

src/librustc/infer/combine.rs
src/librustc/infer/type_variable.rs

index 5ce30484ede0027aab5c595d58a5ef906067ea86..fda08eba0213521cdafd89c2446ae08c2e589f3b 100644 (file)
@@ -49,6 +49,7 @@
 use traits::PredicateObligations;
 
 use syntax::ast;
+use syntax::util::small_vector::SmallVector;
 use syntax_pos::Span;
 
 #[derive(Clone)]
@@ -181,7 +182,9 @@ pub fn instantiate(&mut self,
                        a_is_expected: bool)
                        -> RelateResult<'tcx, ()>
     {
-        let mut stack = Vec::new();
+        // We use SmallVector here instead of Vec because this code is hot and
+        // it's rare that the stack length exceeds 1.
+        let mut stack = SmallVector::zero();
         stack.push((a_ty, dir, b_vid));
         loop {
             // For each turn of the loop, we extract a tuple
index da9fd1cff2b46ea7da15a33bdf675a3c5b538f9c..3856ea420b0f30c73d4a5e1be4c72972445fedfd 100644 (file)
@@ -12,8 +12,9 @@
 use self::TypeVariableValue::*;
 use self::UndoEntry::*;
 use hir::def_id::{DefId};
-use ty::{self, Ty};
+use syntax::util::small_vector::SmallVector;
 use syntax_pos::Span;
+use ty::{self, Ty};
 
 use std::cmp::min;
 use std::marker::PhantomData;
@@ -149,7 +150,7 @@ pub fn instantiate_and_push(
         &mut self,
         vid: ty::TyVid,
         ty: Ty<'tcx>,
-        stack: &mut Vec<(Ty<'tcx>, RelationDir, ty::TyVid)>)
+        stack: &mut SmallVector<(Ty<'tcx>, RelationDir, ty::TyVid)>)
     {
         debug_assert!(self.root_var(vid) == vid);
         let old_value = {