New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
List.from is fixed length, but loop through list still checks for ioore #10489
Comments
FWIW, if I change fruits to a const list, the JS code looks like: $.main = function() { |
This comment was originally written by ngeoffray@google.com Set owner to ngeoffray@google.com. |
Actually, List.from returns a growable list by default. You need to pass the "growable:false" named parameter to get a fixed list. In this case, it might be able to be specialized because the argument is a literal (growable list, but obviously not modified before being passeed). |
Thanks Lasse, I misread this in the API docs: "The returned list is growable if growable is true, otherwise it's a fixed length list." I read that as "unless you set growable to true, it's fixed" |
So I changed the code to: NBodySystem bodies = new NBodySystem(new List.from([Body.Sun(), but the generated JS is still: for (dx = null, dy = null, dz = null, distance = null, mag = null, i = 0; i < size; i = j) { |
Added this to the Later milestone. |
Added TriageForM5 label. |
Removed TriageForM5 label. |
This comment was originally written by ngeoffray@google.com Added Triaged label. |
This comment was originally written by ngeoffray@google.com Set owner to @floitschG. |
This comment was originally written by @bp74 I tried to optimize some of the JavaScript code generated by dart2js and found the same problem with the ".toList(growable: false)" method. The JavaScript code is smaller and runs faster if i create a "new List(size)" and copy all elements to the new list - which is a non growable list recognized by the compiler. So it would be great if the compiler would optimize for List methods returning non growable lists. |
Removed the owner. |
Removed this from the Later milestone. |
Friendly ping. Did we address this recently? https://code.google.com/p/dart/issues/detail?id=20012 cc @floitschG. |
No. These issues are unrelated. cc @herhut-ggl. |
Removed Oldschool-Milestone-Later label. |
Verified fix in 79a8654 |
Consider this code:
List<String> fruits = new List.from(['apples', 'oranges']);
void main() {
for (int i = 0; i < fruits.length; i++) {
print(fruits[i]);
}
}
this compiles to the following JS code:
$.main = function() {
var i, t1;
for (i = 0; i < $.get$fruits().length; ++i) {
t1 = $.get$fruits();
if (i >= t1.length)
throw $.ioore(i);
$.Primitives_printString($.toString$0(t1[i]));
}
};
I would expect that the constructor for List.from() returns a fixed length list. Thus, dart2js could inline the list length in a for loop and avoid the ioore check.
The text was updated successfully, but these errors were encountered: