Skip to content

Commit b70018c

Browse files
committed
---
yaml --- r: 4321 b: refs/heads/master c: 6c9b90d h: refs/heads/master i: 4319: 6ad4ffe v: v3
1 parent b624c46 commit b70018c

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: f8fa574864a5bd54752fc198438f8c53a8ed5ef0
2+
refs/heads/master: 6c9b90d06a455af08da7ea66977dc4d7d1b4ce1b

trunk/src/comp/middle/trans_alt.rs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,37 @@ fn any_box_pat(m: &match, col: uint) -> bool {
228228
}
229229

230230
type exit_node = {bound: bind_map, from: BasicBlockRef, to: BasicBlockRef};
231-
type mk_fail = fn() -> BasicBlockRef ;
231+
type mk_fail = fn() -> BasicBlockRef;
232+
233+
fn pick_col(m: &match) -> uint {
234+
let scores = ivec::init_elt_mut(0u, ivec::len(m.(0).pats));
235+
for br: match_branch in m {
236+
let i = 0u;
237+
for p: @ast::pat in br.pats {
238+
alt p.node {
239+
ast::pat_lit(_) | ast::pat_tag(_, _) { scores.(i) += 1u; }
240+
_ {}
241+
}
242+
i += 1u;
243+
}
244+
}
245+
let max_score = 0u;
246+
let best_col = 0u;
247+
let i = 0u;
248+
for score: uint in scores {
249+
// Irrefutable columns always go first, they'd only be duplicated in
250+
// the branches.
251+
if score == 0u { ret i; }
252+
// If no irrefutable ones are found, we pick the one with the biggest
253+
// branching factor.
254+
if score > max_score {
255+
max_score = score;
256+
best_col = i;
257+
}
258+
i += 1u;
259+
}
260+
ret best_col;
261+
}
232262

233263
fn compile_submatch(bcx: @block_ctxt, m: &match, vals: ValueRef[],
234264
f: &mk_fail, exits: &mutable exit_node[]) {
@@ -239,10 +269,10 @@ fn compile_submatch(bcx: @block_ctxt, m: &match, vals: ValueRef[],
239269
ret;
240270
}
241271

242-
// FIXME maybe be clever about picking a column.
243-
let col = 0u;
272+
let col = pick_col(m);
244273
let val = vals.(col);
245-
let vals_left = ivec::slice(vals, 1u, ivec::len(vals));
274+
let vals_left = ivec::slice(vals, 0u, col) +
275+
ivec::slice(vals, col + 1u, ivec::len(vals));
246276
let ccx = bcx.fcx.lcx.ccx;
247277
let pat_id = 0;
248278
for br: match_branch in m {

0 commit comments

Comments
 (0)