Re: RFR: JDK-8197594: String#repeat

2018-03-02 Thread Stuart Marks
On 2/28/18 6:34 PM, James Laskey wrote: Thanks Stuart. RE apinote, I was trying to follow the pattern of other older method comments (Roman-style.) Comments/Javadoc in most of these older classes are a mix of styles. Question: if you update/clean-up a method in an older class, should you bring

Re: RFR: JDK-8197594: String#repeat

2018-03-01 Thread Jim Laskey
Ivan, The code is now checked in if you want to test. Cheers, — Jim > On Mar 1, 2018, at 4:20 PM, Ivan Gerasimov wrote: > > Hi Jim! > > I think the copying-loop can be slightly simplified, like this: > > for (; copied < limit - copied; copied <<= 1) { >

Re: RFR: JDK-8197594: String#repeat

2018-03-01 Thread Ivan Gerasimov
Hi Jim! I think the copying-loop can be slightly simplified, like this: for (; copied < limit - copied; copied <<= 1) { System.arraycopy(multiple, 0, multiple, copied, copied); } (didn't actually run it to check for correctness.) With kind regards, Ivan On 2/28/18 8:31 AM,

Re: RFR: JDK-8197594: String#repeat

2018-03-01 Thread Paul Sandoz
> On Mar 1, 2018, at 6:12 AM, Jim Laskey 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

Re: JDK-8197594: String#repeat

2018-03-01 Thread Jim Laskey
> -- > http://bernd.eckenfels.net <http://bernd.eckenfels.net/> > > Von: Jim Laskey <mailto:james.las...@oracle.com> > Gesendet: Mittwoch, 28. Februar 2018 21:01 > An: Core-Libs-Dev <mailto:core-libs-dev@openjdk.java.net> > Betreff: RFR: JDK-8197594: String#repeat &g

Re: JDK-8197594: String#repeat

2018-03-01 Thread Bernd Eckenfels
uce a String exceeding maximum size.“ Gruss Bernd -- http://bernd.eckenfels.net Von: Jim Laskey Gesendet: Mittwoch, 28. Februar 2018 21:01 An: Core-Libs-Dev Betreff: RFR: JDK-8197594: String#repeat Introduction of a new instance method String::repeat to allow an efficient and concise appro

Re: RFR: JDK-8197594: String#repeat

2018-03-01 Thread Claes Redestad
Yes, I think you can squeeze out a 10% improvement or so on some combinations of shortness of String and lowness of repeat count, but at the cost of adding another branch, risking costs due to profile pollution, decreasing chance the method gets inlined etc.. it didn't seem worth the trouble

Re: RFR: JDK-8197594: String#repeat

2018-03-01 Thread Jim Laskey
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 wrote: > > Hi Jim, > > Perhaps

Re: RFR: JDK-8197594: String#repeat

2018-03-01 Thread Jim Laskey
Peter, Very reasonable and worth considering. The main reason the power of 2 copy works well is that the source is (almost) always cached. 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

Re: RFR: JDK-8197594: String#repeat

2018-03-01 Thread Roger Riggs
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

Re: RFR: JDK-8197594: String#repeat

2018-03-01 Thread Peter Levart
Hi, On 03/01/2018 03:13 AM, Paul Sandoz wrote: Hi Jim, Looks good. I like the power of 2 copying. Is this really the fastest way? Say you are doing this: String s = ... 64 bytes ... s.repeat(16384); ...the last arraycopy will be copying 512 KiB from one part of memory to the other part.

Re: RFR: JDK-8197594: String#repeat

2018-02-28 Thread Andrej Golovnin
Hi Jim, src/java.base/share/classes/java/lang/String.java 2972 * This method may be used to create space padding for 2973 * formatting text or zero padding for formatting numbers. 2974 * @param count number of times to repeat 2975 * @return A string composed of this string

Re: RFR: JDK-8197594: String#repeat

2018-02-28 Thread James Laskey
Thanks Stuart. RE apinote, I was trying to follow the pattern of other older method comments (Roman-style.) Comments/Javadoc in most of these older classes are a mix of styles. Question: if you update/clean-up a method in an older class, should you bring the comment/Javadoc up-to-date as well?

Re: RFR: JDK-8197594: String#repeat

2018-02-28 Thread James Laskey
Thanks Paul. Sent from my iPhone > On Feb 28, 2018, at 10: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 */

Re: RFR: JDK-8197594: String#repeat

2018-02-28 Thread Paul Sandoz
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

Re: RFR: JDK-8197594: String#repeat

2018-02-28 Thread Stuart Marks
Hi Jim, Implementation looks good. I'd suggest a couple small editorial changes to the spec: 2966 /** 2967 * Returns a string whose value is the concatenation of this 2968 * string repeated {@code count} times. 2969 * 2970 * If count or length is zero then the empty

RFR: JDK-8197594: String#repeat

2018-02-28 Thread Jim Laskey
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