4 ms·
The article mentions that for optimizing out of bounds checks it uses constant lists or fixed length lists. Could it also optimize the check in a loop if it kno
by hencq 14y ago
The article mentions that for optimizing out of bounds checks it uses constant lists or fixed length lists. Could it also optimize the check in a loop if it knows the loop ends at the end of the list? For example, in the article it mentions:
for (int i = 0; i < v.constraints.length; i++) {
...
c = t1[i];
...
}
Does it do that optimization because it knows v.constraints is fixed length or because it knows that i can never be bigger than v.constraints.length?
- floitsch 14y agodart2js 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).