Skip to content

Commit

Permalink
check_match: get rid of superfluous clones
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardw authored and alexcrichton committed May 14, 2014
1 parent 5bf268d commit 21867fa
Showing 1 changed file with 21 additions and 34 deletions.
55 changes: 21 additions & 34 deletions src/librustc/middle/check_match.rs
Expand Up @@ -266,15 +266,15 @@ fn is_useful(cx: &MatchCheckCtxt, m: &matrix, v: &[@Pat]) -> useful {
val(const_bool(false)),
0u, left_ty)
}
ref u => (*u).clone(),
u => u,
}
}
ty::ty_enum(eid, _) => {
for va in (*ty::enum_variants(cx.tcx, eid)).iter() {
match is_useful_specialized(cx, m, v, variant(va.id),
va.args.len(), left_ty) {
not_useful => (),
ref u => return (*u).clone(),
u => return u,
}
}
not_useful
Expand All @@ -296,7 +296,7 @@ fn is_useful(cx: &MatchCheckCtxt, m: &matrix, v: &[@Pat]) -> useful {
for n in iter::range(0u, max_len + 1) {
match is_useful_specialized(cx, m, v, vec(n), n, left_ty) {
not_useful => (),
ref u => return (*u).clone(),
u => return u,
}
}
not_useful
Expand All @@ -312,21 +312,21 @@ fn is_useful(cx: &MatchCheckCtxt, m: &matrix, v: &[@Pat]) -> useful {
}
}
}
Some(ref ctor) => {
Some(ctor) => {
match is_useful(cx,
&m.iter().filter_map(|r| {
default(cx, r.as_slice())
}).collect::<matrix>(),
v.tail()) {
useful_ => useful(left_ty, (*ctor).clone()),
ref u => (*u).clone(),
useful_ => useful(left_ty, ctor),
u => u,
}
}
}
}
Some(ref v0_ctor) => {
let arity = ctor_arity(cx, v0_ctor, left_ty);
is_useful_specialized(cx, m, v, (*v0_ctor).clone(), arity, left_ty)
Some(v0_ctor) => {
let arity = ctor_arity(cx, &v0_ctor, left_ty);
is_useful_specialized(cx, m, v, v0_ctor, arity, left_ty)
}
}
}
Expand All @@ -345,7 +345,7 @@ fn is_useful_specialized(cx: &MatchCheckCtxt,
cx, &ms, specialize(cx, v, &ctor, arity, lty).unwrap().as_slice());
match could_be_useful {
useful_ => useful(lty, ctor),
ref u => (*u).clone(),
u => u,
}
}

Expand Down Expand Up @@ -416,9 +416,9 @@ fn missing_ctor(cx: &MatchCheckCtxt,
let mut found = Vec::new();
for r in m.iter() {
let r = pat_ctor_id(cx, *r.get(0));
for id in r.iter() {
if !found.contains(id) {
found.push((*id).clone());
for id in r.move_iter() {
if !found.contains(&id) {
found.push(id);
}
}
}
Expand Down Expand Up @@ -820,30 +820,17 @@ fn specialize(cx: &MatchCheckCtxt,
let num_elements = before.len() + after.len();
if num_elements < arity && slice.is_some() {
let mut result = Vec::new();
for pat in before.iter() {
result.push((*pat).clone());
}
for _ in iter::range(0, arity - num_elements) {
result.push(wild())
}
for pat in after.iter() {
result.push((*pat).clone());
}
for pat in r.tail().iter() {
result.push((*pat).clone());
}
let wilds = Vec::from_elem(arity - num_elements, wild());
result.push_all_move(before);
result.push_all_move(wilds);
result.push_all_move(after);
result.push_all(r.tail());
Some(result)
} else if num_elements == arity {
let mut result = Vec::new();
for pat in before.iter() {
result.push((*pat).clone());
}
for pat in after.iter() {
result.push((*pat).clone());
}
for pat in r.tail().iter() {
result.push((*pat).clone());
}
result.push_all_move(before);
result.push_all_move(after);
result.push_all(r.tail());
Some(result)
} else {
None
Expand Down

0 comments on commit 21867fa

Please sign in to comment.