Skip to content

Commit 9270a92

Browse files
committed
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.
1 parent 1e5dab1 commit 9270a92

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/librustc/infer/combine.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ use ty::relate::{RelateResult, TypeRelation};
4949
use traits::PredicateObligations;
5050

5151
use syntax::ast;
52+
use syntax::util::small_vector::SmallVector;
5253
use syntax_pos::Span;
5354

5455
#[derive(Clone)]
@@ -181,7 +182,9 @@ impl<'infcx, 'gcx, 'tcx> CombineFields<'infcx, 'gcx, 'tcx> {
181182
a_is_expected: bool)
182183
-> RelateResult<'tcx, ()>
183184
{
184-
let mut stack = Vec::new();
185+
// We use SmallVector here instead of Vec because this code is hot and
186+
// it's rare that the stack length exceeds 1.
187+
let mut stack = SmallVector::zero();
185188
stack.push((a_ty, dir, b_vid));
186189
loop {
187190
// For each turn of the loop, we extract a tuple

src/librustc/infer/type_variable.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ pub use self::RelationDir::*;
1212
use self::TypeVariableValue::*;
1313
use self::UndoEntry::*;
1414
use hir::def_id::{DefId};
15-
use ty::{self, Ty};
15+
use syntax::util::small_vector::SmallVector;
1616
use syntax_pos::Span;
17+
use ty::{self, Ty};
1718

1819
use std::cmp::min;
1920
use std::marker::PhantomData;
@@ -149,7 +150,7 @@ impl<'tcx> TypeVariableTable<'tcx> {
149150
&mut self,
150151
vid: ty::TyVid,
151152
ty: Ty<'tcx>,
152-
stack: &mut Vec<(Ty<'tcx>, RelationDir, ty::TyVid)>)
153+
stack: &mut SmallVector<(Ty<'tcx>, RelationDir, ty::TyVid)>)
153154
{
154155
debug_assert!(self.root_var(vid) == vid);
155156
let old_value = {

0 commit comments

Comments
 (0)