RFR: 8132995: Matcher$ImmutableMatchResult should be optimized to reduce space usage [v2]
Stuart Marks
smarks at openjdk.org
Wed May 17 05:27:44 UTC 2023
On Thu, 11 May 2023 09:22:44 GMT, Raffaello Giulietti <rgiulietti at openjdk.org> wrote:
>> When appropriate and useful, copies only the relevant portion of the `CharSequence` to the match result.
>
> Raffaello Giulietti has updated the pull request incrementally with one additional commit since the last revision:
>
> Added some randomness in tests.
src/java.base/share/classes/java/util/regex/Matcher.java line 271:
> 269: return text instanceof String s ? s : text.subSequence(first, last).toString();
> 270: }
> 271:
I'd think we'd want to get a subSequence of any text, regardless of whether it's a String or some other CharSequence. This could result in a savings if there is a match result (or several match results) from find() operation(s) on a large String, when the matched text is relative small.
I'd also merge this into the creation of the MatchResult. The offset needs to be stored because the start/end locations are indexes into the original text, but we're storing only a subSequence of the original text. However, if we always store a subSequence, the offset is always the same as `first`.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/13231#discussion_r1195953652
More information about the core-libs-dev
mailing list