RFR: JDK-8197594: String#repeat
Jim Laskey
james.laskey at oracle.com
Thu Mar 1 14:15:35 UTC 2018
Roger,
Claes did some performance tests against an earlier implementation where I was doing just that. We determined that the performance difference was lost in the noise.
Cheers,
— Jim
> On Mar 1, 2018, at 10:11 AM, Roger Riggs <Roger.Riggs at oracle.com> wrote:
>
> Hi Jim,
>
> Perhaps premature optimization...
>
> Have you done any JMH tests on the expected string content and sizes. The optimization for single 8-bit characters
> is good but for short strings like inserting spaces for tab stops, " ".repeat(5), will suffer the overhead of Arraycopy
> for very small/short or non-8-bit strings. Perhaps use a regular loop below some threshold ( limit < 32).
> Maybe the intrinsic already handles this efficiently or it is not important enough to optimize.
>
> I would not expect to see many very long repeats or long strings being repeated.
> And I would leave cache-effect optimizations to the implementation of Arraycopy.
>
> Thanks, Roger
>
> On 2/28/2018 9:13 PM, Paul Sandoz wrote:
>> Hi Jim,
>>
>> Looks good. I like the power of 2 copying.
>>
>>
>> 2978 * @throws IllegalArgumentException if the {@code count} is
>> 2979 * negative.
>> 2980 */
>> 2981 public String repeat(int count) {
>>
>> Missing @since11 on the method.
>>
>>
>> Like Stuart suggests, turn the explanatory text into an api note, perhaps with a small code sample.
>>
>> Thanks,
>> Paul.
>>
>>> On Feb 28, 2018, at 8:31 AM, Jim Laskey <james.laskey at oracle.com> wrote:
>>>
>>> Introduction of a new instance method String::repeat to allow an efficient and concise approach for generating repeated character sequences as strings.
>>>
>>> Performance information in JBS.
>>>
>>> Thank you.
>>>
>>> Cheers,
>>>
>>> — Jim
>>>
>>>
>>> JBS: https://bugs.openjdk.java.net/browse/JDK-8197594 <https://bugs.openjdk.java.net/browse/JDK-8197594>
>>> CSR: https://bugs.openjdk.java.net/browse/JDK-8198296
>>> <http://cr.openjdk.java.net/~jlaskey/8197594/String.html>
>>> Webrev: http://cr.openjdk.java.net/~jlaskey/8197594/webrev-02/index.html <http://cr.openjdk.java.net/~jlaskey/8197594/webrev-02/index.html>
>>> JavaDoc: http://cr.openjdk.java.net/~jlaskey/8197594/String.html <http://cr.openjdk.java.net/~jlaskey/8197594/String.html>
>>>
>>>
>>>
>
More information about the core-libs-dev
mailing list