RFR: JDK-8197594: String#repeat

Paul Sandoz paul.sandoz at oracle.com
Thu Mar 1 17:04:57 UTC 2018

> On Mar 1, 2018, at 6:12 AM, Jim Laskey <james.laskey at oracle.com> wrote:
> Peter,
> Very reasonable and worth considering. The main reason the power of 2 copy works well is that the source is (almost) always cached.

That was my thinking too, the current approach is fine for anticipated string sizes and repeats. 

We could consider more optimal and general cache friendly approaches but the API cost is likely higher than the benefit e.g. if we add a method to Arrays then 8 + 9 others (all primitives + ref and offset accepting methods) tend to come along for the ride.


> I thought about this a bit at the beginning and wondered about introducing Arrays.fill(T[] dst, T[] src) where dst is filled repeatedly from src. This can then become an intrinsic and “do the right thing” based on hardware. String::repeat can be adapted later. I didn’t pursue because I lacked other use cases.
> File a performance against the implementation (once checked in) and we can see what the performance team thinks.

> Cheers,
> — Jim

More information about the core-libs-dev mailing list