about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-10-23 20:10:16 -0700
committerGitHub <noreply@github.com>2016-10-23 20:10:16 -0700
commitac468b67bffc6c386dd04b7955eec013ef99dc39 (patch)
tree73e4c8f257f74731fd0e7d934a70a3ed44b2135b /src
parent1e5dab1da04143a454a4f3d7e3f835ce990b437a (diff)
parent9270a9217a5c44455ec8e5e7b36920ab71816004 (diff)
downloadrust-ac468b67bffc6c386dd04b7955eec013ef99dc39.tar.gz
rust-ac468b67bffc6c386dd04b7955eec013ef99dc39.zip
Auto merge of #37322 - nnethercote:CombineFields-instantiate, r=eddyb
Use `SmallVector` in `CombineFields::instantiate`.

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.
Diffstat (limited to 'src')
-rw-r--r--src/librustc/infer/combine.rs5
-rw-r--r--src/librustc/infer/type_variable.rs5
2 files changed, 7 insertions, 3 deletions
diff --git a/src/librustc/infer/combine.rs b/src/librustc/infer/combine.rs
index 5ce30484ede..fda08eba021 100644
--- a/src/librustc/infer/combine.rs
+++ b/src/librustc/infer/combine.rs
@@ -49,6 +49,7 @@ use ty::relate::{RelateResult, TypeRelation};
 use traits::PredicateObligations;
 
 use syntax::ast;
+use syntax::util::small_vector::SmallVector;
 use syntax_pos::Span;
 
 #[derive(Clone)]
@@ -181,7 +182,9 @@ impl<'infcx, 'gcx, 'tcx> CombineFields<'infcx, 'gcx, 'tcx> {
                        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
diff --git a/src/librustc/infer/type_variable.rs b/src/librustc/infer/type_variable.rs
index da9fd1cff2b..3856ea420b0 100644
--- a/src/librustc/infer/type_variable.rs
+++ b/src/librustc/infer/type_variable.rs
@@ -12,8 +12,9 @@ pub use self::RelationDir::*;
 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 @@ impl<'tcx> TypeVariableTable<'tcx> {
         &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 = {