google / google/closure-compiler

[Potential Optimization] Multiple "0 comparisons" with guarenteed positive numbers can be added.

Open
#3,567 1 comment 0 reactions 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.