Skip to content

Commit dffed2b

Browse files
pcwaltonemberian
authored andcommitted
---
yaml --- r: 66398 b: refs/heads/master c: f463e69 h: refs/heads/master v: v3
1 parent df5184c commit dffed2b

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 90ad44428759617723f2f4630aa22bbed6f33aaf
2+
refs/heads/master: f463e69d203ffdd1a0c6c73612a0ba514a700a78
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 18e3db7392d2d0697b7e27d6d986139960144d85
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9

trunk/src/librustc/middle/trans/build.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -610,12 +610,21 @@ pub fn GEP(cx: block, Pointer: ValueRef, Indices: &[ValueRef]) -> ValueRef {
610610

611611
// Simple wrapper around GEP that takes an array of ints and wraps them
612612
// in C_i32()
613-
//
614-
// FIXME #6571: Use a small-vector optimization to avoid allocations here.
613+
#[inline]
615614
pub fn GEPi(cx: block, base: ValueRef, ixs: &[uint]) -> ValueRef {
616-
let v = do vec::map(ixs) |i| { C_i32(*i as i32) };
617-
count_insn(cx, "gepi");
618-
return InBoundsGEP(cx, base, v);
615+
// Small vector optimization. This should catch 100% of the cases that
616+
// we care about.
617+
if ixs.len() < 16 {
618+
let mut small_vec = [ C_i32(0), ..16 ];
619+
for ixs.eachi |i, &ix| {
620+
small_vec[i] = C_i32(ix as i32)
621+
}
622+
InBoundsGEP(cx, base, small_vec.slice(0, ixs.len()))
623+
} else {
624+
let v = do vec::map(ixs) |i| { C_i32(*i as i32) };
625+
count_insn(cx, "gepi");
626+
InBoundsGEP(cx, base, v)
627+
}
619628
}
620629

621630
pub fn InBoundsGEP(cx: block, Pointer: ValueRef, Indices: &[ValueRef]) -> ValueRef {

0 commit comments

Comments
 (0)