[TRIVIAL] Fast-path for String.subsring(n,n)
Сергей Цыпанов
sergei.tsypanov at yandex.ru
Wed Feb 26 10:01:34 UTC 2020
Hello,
I've moved this fast-path into both StringUTF16.newString/StringLatin1.newString.
Patch is attached.
Test-tier1 is OK, though I have a question about StringLatin1/StringUTF16.stripLeading()
and StringLatin1/StringUTF16.stripTrailing():
Currently we have
public static String stripLeading(byte[] value) {
int left = indexOfNonWhitespace(value);
if (left == value.length) {
return "";
}
return (left != 0) ? newString(value, left, value.length - left) : null;
}
With the patch we change behaviour of this method for the case when value.length == 0:
public static String stripLeading(byte[] value) {
int left = indexOfNonWhitespace(value);
return (left != 0) ? newString(value, left, value.length - left) : null;
}
Unlike original method this code returns null instead of "" for empty array.
This does not affect caller (String.stripLeading()) i. e. visible behaviour
remains the same for String user, but is it OK in general?
If yes, is there anyone who could sponsor this change?
With best regards,
Sergey Tsypanov
25.02.2020, 18:41, "Ivan Gerasimov" <ivan.gerasimov at oracle.com>:
> Hi Sergei!
>
> Wouldn't it make sense to incorporate this fast path into
> StringUTF16.newString/StringLatin1.newString?
>
> This way other callers of these methods will also benefit from it.
>
> In particular, StringLatin1/StringUTF16.stripLeading(),
> StringLatin1/StringUTF16.stripTrailing() and maybe others could be
> slightly simplified.
>
> With kind regards,
>
> Ivan
>
> On 2/25/20 7:42 AM, Сергей Цыпанов wrote:
>> Hello,
>>
>> current implementation of String.substring(int,int) has a fast-path for the case when beginIndex = 0 and endIndex = length.
>>
>> I think there should be similar fast-path for the case beginIndex = endIndex (asuming both are valid):
> --
> With kind regards,
> Ivan Gerasimov
-------------- next part --------------
A non-text attachment was scrubbed...
Name: newString.patch
Type: text/x-diff
Size: 3455 bytes
Desc: not available
URL: <https://mail.openjdk.java.net/pipermail/core-libs-dev/attachments/20200226/bb7eac67/newString-0001.patch>
More information about the core-libs-dev
mailing list