File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Expand file tree Collapse file tree 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] {
149149 do as_mut_buf( v) |p, _len| {
150150 let mut i: uint = 0 u;
151151 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) ) ;
154153 i += 1 u;
155154 }
156155 }
@@ -166,7 +165,20 @@ pub fn from_fn<T>(n_elts: uint, op: old_iter::InitOp<T>) -> ~[T] {
166165 * to the value `t`.
167166 */
168167pub 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+ }
170182}
171183
172184/// Creates a new unique vector with the same contents as the slice
You can’t perform that action at this time.
0 commit comments