3 ms·
dart2js does range analyses. For example the indexing in the following example will not do any bounds checks. for (int i = 0; i < list.length; i++) {
by floitsch 14y ago
dart2js does range analyses.
For example the indexing in the following example will not do any bounds checks.
for (int i = 0; i < list.length; i++) {
var t = list[i];
}
Things get more complicated when there are function calls in the loop-body that could potentially change the list-length:
for (int i = 0; i < list.length; i++) {
foo("random call", list); // could have side-effect.
var t = list[i]; // needs to check bounds.
}
However if the element is read before the call, it should still work:
for (int i = 0; i < list.length; i++) {
var t = list[i]; // no need for bounds-check.
foo("random call", list); // could have side-effect.
}
The last example doesn't need a bounds-check, but it does need to reload the length-field of the list at every iteration (in case the length changed).