Dart SDK のアルゴリズムの有効性がわかりません。
アルゴリズムは次のとおりです(リストファクトリーdart:core
、ファイルlist.dart
)
factory List.from(Iterable other, { bool growable: true }) {
List<E> list = new List<E>();
for (E e in other) {
list.add(e);
}
if (growable) return list;
int length = list.length;
List<E> fixedList = new List<E>(length);
for (int i = 0; i < length; i ) {
fixedList[i] = list[i];
}
return fixedList;
}
growable
の場合false
、両方のリストが作成されます。
List<E> list = new List<E>();
List<E> fixedList = new List<E>(length);
ただし、この場合のリスト #1 の作成は、 の複製であるため冗長ですIterable other
。CPU時間とメモリを浪費するだけです。
growable
この場合、このアルゴリズムは不要なリスト #1 ( is )を作成しないため、より効率的になりますfalse
。
factory List.from(Iterable other, { bool growable: true }) {
if(growable) {
List<E> list = new List<E>();
for (E e in other) {
list.add(e);
}
return list;
}
List<E> fixedList = new List<E>(other.length);
var i = 0;
for (E e in other) {
fixedList[i++] = e;
}
return fixedList;
}
それとも、私が間違っていて、プログラミングの微妙な点を見逃しているのでしょうか?