As per this comment on reddit, there is a usage pattern for StringBuilder that we've never really considered, and that seems to be extremely difficult to optimize given the current implementation.
But if StringBuilder were to store its characters in a Java LongArray, we could optimize the for loop to use by-index access.
The question is whether we could then make StringBuilder.string efficient enough. I think it's likely that we could, with some finesse. If not, then perhaps we just need a separate class (StringBuffer??) that behaves like this. The idea being that it's not meant for "building strings", but for aggregating and reading Characters.
Those really are two separate usage patterns, actually.
As per this comment on reddit, there is a usage pattern for
StringBuilderthat we've never really considered, and that seems to be extremely difficult to optimize given the current implementation.But if
StringBuilderwere to store its characters in a JavaLongArray, we could optimize theforloop to use by-index access.The question is whether we could then make
StringBuilder.stringefficient enough. I think it's likely that we could, with some finesse. If not, then perhaps we just need a separate class (StringBuffer??) that behaves like this. The idea being that it's not meant for "building strings", but for aggregating and readingCharacters.Those really are two separate usage patterns, actually.