-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dart2js better code for "is type" check #9971
Comments
Added Area-Dart2JS, C3, Triaged labels. |
Added this to the Later milestone. |
In the general case the getInterceptor call is needed when there may be DOM objects floating around. For example, a DOM Storage object in JavaScript materializes the keys and values as properties. So it is possible for the Storage object to "accidentally" be truthy for "t1.$isfoo" following a statement like window.localStorage['$isfoo'] = '1' dart2js should definitely be generating a faster, specialized version of getInterceptor. Marked this as being blocked by #9732. |
Added TriageForM5 label. |
Removed TriageForM5 label. |
This comment was originally written by ngeoffray@google.com The getInterceptor call gets removed now, so I'll assume this bug as staled. Added AssumedStale label. |
This issue was originally filed by @bp74
What steps will reproduce the problem?
I tried to optimize the dart2js output for a hot function in my code. The generated code get's a lot better if i add a type check. But the code for the type check itself is not optimal. The code below shows the code of a simple type check for class "foo":
var x = [new foo()];
void main() {
if (x[0] is! foo) print("is not foo");
}
$.main = function() {
var t1 = $.$index$as($.get$x(), 0);
if (typeof t1 !== "object" || t1 === null || !$.getInterceptor(t1).$isfoo)
$.Primitives_printString("is not foo");
};
$.getInterceptor = function(receiver) {
if (typeof receiver == "number") {
if (Math.floor(receiver) == receiver) return $.JSInt.prototype;
return $.JSDouble.prototype;
}
if (typeof receiver == "string") return $.JSString.prototype;
if (receiver == null) return $.JSNull.prototype;
if (typeof receiver == "function") return $.JSFunction.prototype;
if (typeof receiver == "boolean") return $.JSBool.prototype;
if (receiver.constructor == Array) return $.JSArray.prototype;
if (typeof receiver != "object") return receiver;
if (receiver instanceof $.Object) return receiver;
if (Object.getPrototypeOf(receiver) === Object.prototype) return $.Interceptor.prototype;
return $.getNativeInterceptor(receiver);
};
What is the expected output? What do you see instead?
if (typeof t1 !== "object" || t1 === null || !$.getInterceptor(t1).$isfoo)
Is the call to getInterceptor really needed? Most of the if-checks in getInterceptor will fail because it is guaranteed that "typeof receiver" is an object and receiver is surely not null. Do i need an interceptor at all, would it be okay to just check "t1.$isFoo" ?
What version of the product are you using? On what operating system?
Dart Editor version 0.1.2_r21625
Dart SDK version 0.1.2.0_r21623
Please provide any additional information below.
The text was updated successfully, but these errors were encountered: