On Wed, 14 May 2025 20:14:21 GMT, Brian Burkhalter <b...@openjdk.org> wrote:
>> I think this may be a good way to reduce redundant allocation if the >> CharSequence's subsequence is a simple view (frequently the case for user >> ones) or a String (for StringBuilder, String) > > I have no idea whether `subSequence` is more performant than `getChars` but > it seems cleaner. In any case, at this point we are concerned primarily with > the APIs getting into JDK 25. We can improve performance after that. Actually I am working on exact these optimizations right now and do not like the idea that I have to file another JBS and PR just for a single code line. As `subSequence` typically *does* a copy (to not hold the original full text in-memory for the lifetime of a possibly single-character sub sequence), unless otherwise proven, `getChars` will always be faster. Having said that, I need to say, that I do not second what Chen said. In reality I have never seen "simple views", in particular not "frequently". ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/24728#discussion_r2089697023