Description
This issue was originally filed by @bp74
What steps will reproduce the problem?
I have a very hot function and tried to optimize it for dart2js. Thereby i noticed an optimization opportunity which doesn't improve the performance but still it would be a nice if the compiler knows how to optimize it.
Dart code (first version):
if (foo != null && !identical(foo, _foo)) {
// Do stuff
}
Dart code (second version):
if (foo!= null) {
if (!identical(foo, _foo)) {
// Do stuff
}
}
What is the expected output? What do you see instead?
The first version generates this JavaScript code:
var t1;
if (foo != null) {
t1 = this._foo;
t1 = foo == null ? t1 != null : foo !== t1;
} else
t1 = false;
if (t1) {
// Do stuff
}
The second version generates this JavaScript code:
var t1;
if (foo != null) {
t1 = this._foo;
if (foo == null ? t1 != null : foo !== t1) {
// Do stuff
}
}
I can imagine that the first version of the Dart code may be harder to optimize, but the second version should be easier because the test for "foo == null" is always false in this block. In a perfect world the compiler would recognize this in the first version too and the JavaScript code would look like this:
if (foo != null && foo !== _foo) {
// Do stuff
}
What version of the product are you using? On what operating system?
Dart Editor version 1.2.0.dev_01_00 (DEV)
Dart SDK version 1.2.0-dev.1.0
Please provide any additional information below.