File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -1199,7 +1199,22 @@ pub fn[A] iter2(self : T[A]) -> Iter2[Int, A] {
1199
1199
/// Convert the iterator into a list. Preserves order of elements.
1200
1200
/// If the order of elements is not important, use `from_iter_rev` instead.
1201
1201
pub fn [A ] from_iter (iter : Iter [A ]) -> T [A ] {
1202
- iter .fold (init = Empty , fn (acc , e ) { More (e , tail = acc ) }).reverse_inplace ()
1202
+ let mut res = Empty
1203
+ let mut ptr = Empty
1204
+ for x in iter {
1205
+ match (res , ptr ) {
1206
+ (Empty , _ ) => {
1207
+ res = More (x , tail = Empty )
1208
+ ptr = res
1209
+ }
1210
+ (More (_ ), More (_ ) as ptr_ ) => {
1211
+ ptr_ .tail = More (x , tail = Empty )
1212
+ ptr = ptr_ .tail
1213
+ }
1214
+ (_ , _ ) => abort ("unreachable" )
1215
+ }
1216
+ }
1217
+ res
1203
1218
}
1204
1219
1205
1220
///|
You can’t perform that action at this time.
0 commit comments