Skip to content

Commit 68ecd06

Browse files
committed
Small optimisation of most common cases
1 parent f309dc3 commit 68ecd06

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/copies.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use rustc_front::hir::*;
44
use std::collections::HashMap;
55
use std::collections::hash_map::Entry;
66
use syntax::parse::token::InternedString;
7+
use syntax::util::small_vector::SmallVector;
78
use utils::{SpanlessEq, SpanlessHash};
89
use utils::{get_parent_expr, in_macro, span_note_and_lint};
910

@@ -78,8 +79,8 @@ impl LateLintPass for CopyAndPaste {
7879
}
7980

8081
let (conds, blocks) = if_sequence(expr);
81-
lint_same_then_else(cx, &blocks);
82-
lint_same_cond(cx, &conds);
82+
lint_same_then_else(cx, blocks.as_slice());
83+
lint_same_cond(cx, conds.as_slice());
8384
lint_match_arms(cx, expr);
8485
}
8586
}
@@ -143,9 +144,9 @@ fn lint_match_arms(cx: &LateContext, expr: &Expr) {
143144
/// Return the list of condition expressions and the list of blocks in a sequence of `if/else`.
144145
/// Eg. would return `([a, b], [c, d, e])` for the expression
145146
/// `if a { c } else if b { d } else { e }`.
146-
fn if_sequence(mut expr: &Expr) -> (Vec<&Expr>, Vec<&Block>) {
147-
let mut conds = vec![];
148-
let mut blocks = vec![];
147+
fn if_sequence(mut expr: &Expr) -> (SmallVector<&Expr>, SmallVector<&Block>) {
148+
let mut conds = SmallVector::zero();
149+
let mut blocks = SmallVector::zero();
149150

150151
while let ExprIf(ref cond, ref then_block, ref else_expr) = expr.node {
151152
conds.push(&**cond);

0 commit comments

Comments
 (0)