File tree 1 file changed +15
-3
lines changed
1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -149,8 +149,7 @@ pub fn from_fn<T>(n_elts: uint, op: old_iter::InitOp<T>) -> ~[T] {
149
149
do as_mut_buf( v) |p, _len| {
150
150
let mut i: uint = 0 u;
151
151
while i < n_elts {
152
- intrinsics:: move_val_init ( & mut ( * ptr:: mut_offset ( p, i) ) ,
153
- op ( i) ) ;
152
+ intrinsics:: move_val_init ( & mut ( * ptr:: mut_offset ( p, i) ) , op ( i) ) ;
154
153
i += 1 u;
155
154
}
156
155
}
@@ -166,7 +165,20 @@ pub fn from_fn<T>(n_elts: uint, op: old_iter::InitOp<T>) -> ~[T] {
166
165
* to the value `t`.
167
166
*/
168
167
pub fn from_elem < T : Copy > ( n_elts : uint , t : T ) -> ~[ T ] {
169
- from_fn ( n_elts, |_i| copy t)
168
+ // hack: manually inline from_fn for 2x plus speedup (sadly very important, from_elem is a
169
+ // bottleneck in borrowck!)
170
+ unsafe {
171
+ let mut v = with_capacity ( n_elts) ;
172
+ do as_mut_buf( v) |p, _len| {
173
+ let mut i = 0 u;
174
+ while i < n_elts {
175
+ intrinsics:: move_val_init ( & mut ( * ptr:: mut_offset ( p, i) ) , copy t) ;
176
+ i += 1 u;
177
+ }
178
+ }
179
+ raw:: set_len ( & mut v, n_elts) ;
180
+ v
181
+ }
170
182
}
171
183
172
184
/// Creates a new unique vector with the same contents as the slice
You can’t perform that action at this time.
0 commit comments