Performance improvements for ElementBuilder. Note that this change looks enormous, but most of the files contain trivial API changes.

The current version of ElementBuilder involves a lot of casting, which results in thousands of dynamic casts (runtime type checks) when building a large table.  This change removes most of the unnecessary casts.

All of the endXXX() methods now return void instead of a parameterized return value.  The parameterized return value must be cast, and rightfully so because its returning the type of the parent builder.  That results in a dynamic cast for every element in the structure.  In practice, it usually isn't necessary or practical to continue building after calling end().  I originally put in the return value figuring that some people might find it useful, but not at the expense of performance. Likewise, all of the startXXX() methods in DomBuilderImpl and HtmlBuilderImpl now return a builder directly instead of going through a generic start() method.  The generic start method had a parameterized return type, which forces a dynamic cast.

All arrays and Collections require a dynamic cast every time an element is added.  ElementBuilderImpl used two Lists to maintain the stack of builders and the stack of tagNames, and DomBuilderImpl used a List to maintain the Stack of Elements.  I created a simple linked list based stack called FastPeekStack that replaces both stacks in ElementBuilderImpl and does not require any dynamic casts.  I removed the stack completely in DomBuilderImpl and instead used calls to currentElement.getParentElement() to move back up the stack. Maps have the same problem, so I replaced the Maps used as caches in DomStylesBuilder and HtmlStylesBuilder with JavaScriptObjects, and I use native JSNI to manually put/get items on the map.

In many cases, there were unnecessary method calls that added to the total time. In all of the HtmlElementBuilder implementations, setting an attribute calls attribute(name,value), which escapes the name and value, even though the name is a constant and does not need to be escaped. The escape call requires five String.indexOf() checks. I added a package protected trustedAttribute(name, value) method that does not escape the name, but still escapes the value. In addition, the version of attribute that takes an integer value no longer converts the value to a string and escapes it.  We append the integer directly, as integers are safe html.

Finally, there are some bug fixes. ElementBuilderFactory#createCheckInput() is not ElementBuilderFactory#createCheckboxInput(), and it correctly sets the input type to "checkbox" instead of "check".

Review at http://gwt-code-reviews.appspot.com/1477801

Review by: rdcastro@google.com

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@10450 8db76d5a-ed1c-0410-87a9-c151d255dfc7
96 files changed