Manuel Carrasco Moñino has posted comments on this change.
Change subject: Adds Node#removeAllChildren.
......................................................................
Patch Set 2:
The point of using Java vs JSNI is that since java methods could be used in
other parts, the usage of native functions like this.removeChild() would
eventually be wrapped by the compiler with a function like rc().
In theory, this approach implies that native functions with long names
would be replaced with short-name functions resulting a smaller code,
noticeable if we call the method several times.
I have made a couple of tests to check what the compiler does, and I've
seen that the compiler always is inlining calls to the java method
removeChild() although it is used several times.
I dont know if the compiler is taking in account the number of times a
method is used before considering whether is better to inline it, but
aparently it is not doing so, I would ask to the mainling-list though.
- Java Implementation of removeAllChildren:
public final void removeAllChildrenJava() {
Node n;
while((n = getLastChild()) != null)
removeChild(n);
}
- Application Java Code
Window.alert("REMOVE-JAVA");
Document.get().getBody().removeAllChildrenJava();
Document.get().getBody().removeChild(null);
- Resulting Js code:
Rg('REMOVE-JAVA');tb($doc.body);$doc.body.removeChild(null)}
function tb(a){var b;while(b=a.lastChild)a.removeChild(b)};
- JSNI Implementation of removeAllChildren:
public native final void removeAllChildrenJsni() /*-{
while(this.lasChild) {
this.removeChild(this.lasChild());
}
}-*/;
- Application Java Code
Window.alert("REMOVE-JNSI");
Document.get().getBody().removeAllChildrenJsni();
Document.get().getBody().removeChild(null);
- Resulting Js code:
Rg('REMOVE-JNSI');ub($doc.body);$doc.body.removeChild(null)}
function ub(a){while(a.lasChild){a.removeChild(a.lasChild())}}
As you can see the code is almost the same in both cases, and in my tests
they perform the same in prod (not in dev-mode though).
But the thing is that if gwtc were not inlined the functions the code
should be a little smaller, something like this:
function tb(a){var b;while(b=lc(a))rc(b)};
Anyway, this is just a curiosity, not a deal in this case.
--
To view, visit https://gwt-review.googlesource.com/3511
To unsubscribe, visit https://gwt-review.googlesource.com/settings
Gerrit-MessageType: comment
Gerrit-Change-Id: Ic607bf6523a41c0ee4020a12e8505b1d8b39d916
Gerrit-PatchSet: 2
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Goktug Gokdogan <[email protected]>
Gerrit-Reviewer: Daniel Kurka <[email protected]>
Gerrit-Reviewer: Goktug Gokdogan <[email protected]>
Gerrit-Reviewer: Leeroy Jenkins <[email protected]>
Gerrit-Reviewer: Manuel Carrasco Moñino <[email protected]>
Gerrit-HasComments: No
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors
---
You received this message because you are subscribed to the Google Groups "GWT Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.