excessive new StringWriter usage

In ST.toString(), I create a new StringWriter every time I render a template to string:

	public String toString(int lineWidth) {
		StringWriter out = new StringWriter();
		// Write the output to a StringWriter
		StringTemplateWriter wr = group.getStringTemplateWriter(out);
        ...

Worse, that getStringTemplateWriter() call creates a new AutoIndentWriter each time. For very large and highly nested output structures with lots of embedded STs, many many of these object will be created. Worse, there is a lot of data copying from one StringWriter to another as it includes all of the embedded templates together.

Find a way to reuse a single string writer for the whole system and use a Singleton AutoIndentWriter. Should be easy by using write(aSharedAutoIndentWriter). There may be some issues with the line wrap and indentation state.

Labels

todo todo Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Nov 09, 2006

    Kay Röpke says:

    this is ST-4: http://www.antlr.org:8888/browse/ST-4