google / google/closure-compiler
[Potential Optimization] Multiple "0 comparisons" with guarenteed positive numbers can be added.
Open
feat
P4
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
For example, if the compiler knows for a fact that a given set of numbers can only ever be positive or 0, and multiple bounds checks are being performed, the following is possible:
```js
/**
* @param {Array} a
* @param {Array} b
*/
function test(a, b) {
return a.length === 0 && b.length === 0;
}
```
->
```js
function test(a, b) {
return a.length + b.length === 0;
}
```
Contributor guide
Assessment
This issue has not been assessed yet.