RFR: String.join(), StringJoiner additions (original) (raw)
Martin Buchholz martinrb at google.com
Mon Apr 15 20:36:19 UTC 2013
- Previous message: RFR: String.join(), StringJoiner additions
- Next message: RFR: String.join(), StringJoiner additions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Thanks for the pointer. Yeah, that's one the pieces I think we should have to do an optimal job of rewriting collection toString methods.
On Mon, Apr 15, 2013 at 1:03 PM, Steven Schlansker < stevenschlansker at gmail.com> wrote:
On Apr 15, 2013, at 12:21 PM, Martin Buchholz <martinrb at google.com> wrote: > On Mon, Apr 15, 2013 at 11:31 AM, Martin Buchholz <martinrb at google.com_ _>wrote: > >> >> OTOH, I'm guessing you are trying to improve the performance of operations >> like List.toString. >> More efficient (single copy char[]) would be to collect all the >> sub-CharSequences in a CharSequence[], pre-compute the final length of the >> char[], allocate an array of exactly the required length, and create the >> final string directly from that using the package-private constructor (but >> in the unlikely event that a subsequence changed in size while concat'ing, >> be prepared to resize the array). >> > > Proceeding further along this train of thought, I might start with > AbstractCollection.toString() (and similar methods) and attempt to make it > maximally efficient. > Maybe add a method to JavaLangAccess to make a String directly from a > perfectly sized array (as needed elsewhere?). Maybe create a > StringBuilder-like class that works better for typical use cases? For what it's worth, a patch that I contributed and Mike (and others) then rewrote contains this functionality already:
http://cr.openjdk.java.net/~mduigou/JDK-8006627/2/webrev/src/share/classes/sun/misc/JavaLangAccess.java.patch It's not merged yet though.
- Previous message: RFR: String.join(), StringJoiner additions
- Next message: RFR: String.join(), StringJoiner additions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]