I'm sure that in some cases, there is no way around creating a StringBuilder, adding each character or escaped version of a character, and then using the resulting String. But since the methods of interest for serialization all involve a Writer, it is almost certainly more efficient for larger content strings (and probably most other cases) to have the escaped characters be written directly to a Writer or Appendable.
I suggest the following refactoring to support this:
It would also then be useful to add to HtmlSerializer a version of escapeText that accepts the Writer being used for serialization, which could delegate to a new version of Utils.escapeHtml, and so forth.
Let me know if you're interested in my help implementing such a change; and if so, if there are any details you would like to specify about how I do so.
Hi Dave,
I'm always very interested in any help offered!
For this refactoring, the best approach is to create a single patch that I can apply to the trunk; I'll then run the unit tests, and if they're OK, I'll commit the patch and it'll be in the next release.