Closed
Description
The current proposed semantics given by the spread collections proposal specify spreading into a list using the Iterable
protocol. So we have that
foo(List<int> x) => [...x];
de-sugars to (roughly):
foo(List<int> x) {
var tmp = <int>[];
for(var e in x) {
tmp.add(e);
}
return tmp;
}
We could, in the case where we are statically spreading something of type List
, use a direct loop as follows:
foo(List<int> x) {
var len = x.length;
var tmp = List(len);
for(int i = 0; i < len; i++) {
tmp[i] = x[i];
}
return tmp;
}
This is likely to be significantly more efficient, but is not a valid optimization that a compiler can do in the absence of extra information about the implementation type of the List
.
Metadata
Metadata
Assignees
Labels
No labels