Some Balancer improvements for performance and compatibility
- Use a doubly-linked list for the AFE list, instead of an array, allowing efficient insertion and removal from the middle, and trivial O(1) lookup of existing elements.
- Use a hashtable of singly-linked lists for storing Noah's Ark buckets, instead of iterating through the entire AFE list on every push.
- Store attributes in an array instead of serializing them in the tokenizer. This allows us to avoid sorting them in the output. For the Noah's Ark clause, the array is copied and then sorted on demand.
- XHTML-style serialization with self-closing tags.
- Clear the AFE list in stopParsing(), otherwise all the BalanceElement objects are kept alive until after serialization, thus using O(N^2) memory (in stack depth N) since the full serialization is stored at each stack level.