8058779: Faster implementation of String.replace(CharSequence, CharSequence)

Xueming Shen xueming.shen at oracle.com
Wed May 27 20:15:33 UTC 2015


On 05/27/2015 01:10 PM, Xueming Shen wrote:
> On 05/27/2015 12:43 PM, Ivan Gerasimov wrote:
>>
>>
>> On 27.05.2015 21:08, Xueming Shen wrote:
>>> targLen = max(1, tagLen);   ?
>>>
>> Well, almost :)
>> With such targLen, (i = j + targLen) would result in i == length() + 1, which will cause IOOBE in the following append().
>>
>> I'm sure the algorithms can be adopted to run correctly with empty target, it just needs some accurate checking.
>>
>> But why can't we consider the first variant of replace()?
>> http://cr.openjdk.java.net/~igerasim/8058779/02/webrev/
>>
>> It's still faster and it can handle larger strings without OOME.  I think this is important.
>>
>> I haven't heard any critics of it except for its relative complexity, comparing to the original code.
>> And we have a backup variant with StringBuilder, if problems are found.
>>
>
>

Personally I prefer not do "buffer management" issue in replace(), StringBuilder is just doing
the job fine. If possible I would avoid to have a special method() to just work a corner case.
"is relative complexity" is a critics. We are trying to see if we can achieve most of the gain
without such complexity.

-Sherman



More information about the core-libs-dev mailing list