On 10/05/2013 07:03, David Holmes wrote:
Short version:
Cache the value returned by toString and use it to copy-construct a
new String on subsequent calls to toString(). Clear the cache on any
mutating operation.
webrev: http://cr.openjdk.java.net/~dholmes/8013395/webrev.v2/
Testing: microbenchmark for toString performance; new regression test
for correctness; JPRT testset core as a sanity check
There is a bit of cringe factor to this one but you've clearly explained
the rational. I think it has to limited to StringBuffer for correctness
reasons. Overall I think it is harmless and is okay. I see Peter's
suggestion about caching the char[] rather than String, seems a good
idea but probably remote issue (not to mention that developers have been
encouraged to move to StringBuilder for many years).
One comment on the test is that at L205 then it could also test a != b.
-Alan.