Skip to content

Commit

Permalink
Use SmallVector in CombineFields::instantiate.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nnethercote committed Oct 24, 2016
1 parent 1e5dab1 commit 9270a92
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/librustc/infer/combine.rs
Expand Up @@ -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)]
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/librustc/infer/type_variable.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit 9270a92

Please sign in to comment.