CharSequence.subSequence optimizations (original) (raw)

Pavel Rappo pavel.rappo at oracle.com
Wed Oct 28 23:35:33 UTC 2015


Hi,

While working with an API that extensively uses java.lang.CharSequence, I've noticed most JDK implementations of CharSequence do not optimize for corner cases in CharSequence.subSequence(int start, int end). Namely,

1. start == end (an empty subsequence)
2. start == 0 && end == CharSequence.this.length() (the same sequence)

It seems to be a valid solution to return a shared empty sequence object and the same (this) sequence in the first and the second case respectively.

I wonder if it's worth investigating pros and cons of introducing these optimizations. Thanks.

P.S. If it's a known issue, I would appreciate if somebody provided a link to a relevant discussion.

-Pavel



More information about the core-libs-dev mailing list