Re: RFR: 8305774: String.join(CharSequence, Iterable) can be optimized if Iterable is a Collection [v2]

2023-04-09 Thread Tingjun Yuan
On Sun, 9 Apr 2023 02:28:37 GMT, Tingjun Yuan wrote: >> In the current implementation of `String.join(CharSequence, Iterable)`, the >> temp array `elems` is always initialized with a length of 8. It will cause >> many array recreations when the `Iterable` contains more than 8 elements. >> Furt

Re: RFR: 8305774: String.join(CharSequence, Iterable) can be optimized if Iterable is a Collection [v3]

2023-04-09 Thread Tingjun Yuan
> In the current implementation of `String.join(CharSequence, Iterable)`, the > temp array `elems` is always initialized with a length of 8. It will cause > many array recreations when the `Iterable` contains more than 8 elements. > Furthermore, it's very common that an `Iterable` is also a `Col

Re: RFR: 8305774: String.join(CharSequence, Iterable) can be optimized if Iterable is a Collection [v2]

2023-04-09 Thread Chen Liang
On Sun, 9 Apr 2023 02:28:37 GMT, Tingjun Yuan wrote: >> In the current implementation of `String.join(CharSequence, Iterable)`, the >> temp array `elems` is always initialized with a length of 8. It will cause >> many array recreations when the `Iterable` contains more than 8 elements. >> Furt

Re: RFR: 8305774: String.join(CharSequence, Iterable) can be optimized if Iterable is a Collection [v2]

2023-04-09 Thread Tingjun Yuan
On Sun, 9 Apr 2023 02:28:37 GMT, Tingjun Yuan wrote: >> In the current implementation of `String.join(CharSequence, Iterable)`, the >> temp array `elems` is always initialized with a length of 8. It will cause >> many array recreations when the `Iterable` contains more than 8 elements. >> Furt

Re: RFR: 8305774: String.join(CharSequence, Iterable) can be optimized if Iterable is a Collection [v2]

2023-04-09 Thread Tingjun Yuan
On Sun, 9 Apr 2023 02:28:37 GMT, Tingjun Yuan wrote: >> In the current implementation of `String.join(CharSequence, Iterable)`, the >> temp array `elems` is always initialized with a length of 8. It will cause >> many array recreations when the `Iterable` contains more than 8 elements. >> Furt

Re: RFR: 8305774: String.join(CharSequence, Iterable) can be optimized if Iterable is a Collection [v2]

2023-04-09 Thread Chen Liang
On Mon, 10 Apr 2023 05:19:05 GMT, Glavo wrote: >> @yuantj As I mentioned earlier, we need to prevent errors from leaking to >> other places, rather than defending against all errors. > >> @Glavo Then why doesn't `ArrayList` trust `toArray()`? If all >> implementations behave correctly, then it

Re: RFR: 8305774: String.join(CharSequence, Iterable) can be optimized if Iterable is a Collection [v2]

2023-04-09 Thread Glavo
On Mon, 10 Apr 2023 05:14:16 GMT, Glavo wrote: >> @Glavo Then why doesn't `ArrayList` trust `toArray()`? If all >> implementations behave correctly, then it should return an `Object[]` >> independent of the original collection, so `ArrayList` should trust it. >> Those who doesn't implement `to

Re: RFR: 8305774: String.join(CharSequence, Iterable) can be optimized if Iterable is a Collection [v2]

2023-04-09 Thread Glavo
On Mon, 10 Apr 2023 05:12:07 GMT, Tingjun Yuan wrote: >> If you really don't trust a collection, then we can't do anything. >> >> Can copying the results of `toArray` ensure accuracy and security? It has >> too many possible problems. Maybe the size of the array is wrong, maybe it >> forgot to

Re: RFR: 8305774: String.join(CharSequence, Iterable) can be optimized if Iterable is a Collection [v2]

2023-04-09 Thread Tingjun Yuan
On Mon, 10 Apr 2023 04:57:09 GMT, Glavo wrote: >> Tingjun Yuan has updated the pull request incrementally with one additional >> commit since the last revision: >> >> Add benchmark > > If you really don't trust a collection, then we can't do anything. > > Can copying the results of `toArray`

Re: RFR: 8305774: String.join(CharSequence, Iterable) can be optimized if Iterable is a Collection [v2]

2023-04-09 Thread Chen Liang
On Sun, 9 Apr 2023 02:28:37 GMT, Tingjun Yuan wrote: >> In the current implementation of `String.join(CharSequence, Iterable)`, the >> temp array `elems` is always initialized with a length of 8. It will cause >> many array recreations when the `Iterable` contains more than 8 elements. >> Furt

Re: RFR: 8305774: String.join(CharSequence, Iterable) can be optimized if Iterable is a Collection [v2]

2023-04-09 Thread Glavo
On Sun, 9 Apr 2023 02:28:37 GMT, Tingjun Yuan wrote: >> In the current implementation of `String.join(CharSequence, Iterable)`, the >> temp array `elems` is always initialized with a length of 8. It will cause >> many array recreations when the `Iterable` contains more than 8 elements. >> Furt

Re: RFR: 8305774: String.join(CharSequence, Iterable) can be optimized if Iterable is a Collection [v2]

2023-04-09 Thread Tingjun Yuan
On Mon, 10 Apr 2023 04:28:34 GMT, Chen Liang wrote: >> Nah. I mean like: >> >> public static String join(CharSequence delimiter, >> Iterable elements) { >> Objects.requireNonNull(delimiter); >> Objects.requireNonNull(elements); >> var delim = delimiter.toS

Re: RFR: 8305774: String.join(CharSequence, Iterable) can be optimized if Iterable is a Collection [v2]

2023-04-09 Thread Glavo
On Mon, 10 Apr 2023 04:28:34 GMT, Chen Liang wrote: > nobody actually trusts this contract I guess not every place should not trust this contract. Where should we distrust contracts and use defensive programming? For example, the constructor of `ArrayList` that accepts `Collection` should not

Re: RFR: 8305774: String.join(CharSequence, Iterable) can be optimized if Iterable is a Collection [v2]

2023-04-09 Thread Chen Liang
On Mon, 10 Apr 2023 03:36:44 GMT, Chen Liang wrote: >> Tingjun Yuan has updated the pull request incrementally with one additional >> commit since the last revision: >> >> Add benchmark > > Nah. I mean like: > > public static String join(CharSequence delimiter, > Iterable ele

Re: RFR: 8305774: String.join(CharSequence, Iterable) can be optimized if Iterable is a Collection [v2]

2023-04-09 Thread Tingjun Yuan
On Mon, 10 Apr 2023 03:36:44 GMT, Chen Liang wrote: >> Tingjun Yuan has updated the pull request incrementally with one additional >> commit since the last revision: >> >> Add benchmark > > Nah. I mean like: > > public static String join(CharSequence delimiter, > Iterable ele

Re: RFR: 8305774: String.join(CharSequence, Iterable) can be optimized if Iterable is a Collection [v2]

2023-04-09 Thread Chen Liang
On Sun, 9 Apr 2023 02:28:37 GMT, Tingjun Yuan wrote: >> In the current implementation of `String.join(CharSequence, Iterable)`, the >> temp array `elems` is always initialized with a length of 8. It will cause >> many array recreations when the `Iterable` contains more than 8 elements. >> Furt

Re: RFR: 8305774: String.join(CharSequence, Iterable) can be optimized if Iterable is a Collection [v2]

2023-04-09 Thread Tingjun Yuan
On Sun, 9 Apr 2023 02:28:37 GMT, Tingjun Yuan wrote: >> In the current implementation of `String.join(CharSequence, Iterable)`, the >> temp array `elems` is always initialized with a length of 8. It will cause >> many array recreations when the `Iterable` contains more than 8 elements. >> Furt

Re: RFR: 8305774: String.join(CharSequence, Iterable) can be optimized if Iterable is a Collection [v2]

2023-04-09 Thread Tingjun Yuan
On Mon, 10 Apr 2023 03:04:20 GMT, Chen Liang wrote: >> @liach Working on that. > > @yuantj Alternatively, you can probably try working on the `toArray` result > of a collection than to allocate a new String array. This might be more > efficient for some implementations like ArrayList as well, i

Re: RFR: 8305774: String.join(CharSequence, Iterable) can be optimized if Iterable is a Collection [v2]

2023-04-09 Thread Tingjun Yuan
On Sun, 9 Apr 2023 02:37:45 GMT, Tingjun Yuan wrote: >> This appears to be a 4% improvement for non-concurrent structures like >> ArrayList or LinkedHashSet, if we ignore the baseline difference (for >> Iterable). This is anticipated as the growth of array size is exponential, >> so the total

Re: RFR: 8305774: String.join(CharSequence, Iterable) can be optimized if Iterable is a Collection [v2]

2023-04-09 Thread Chen Liang
On Sun, 9 Apr 2023 02:37:45 GMT, Tingjun Yuan wrote: >> This appears to be a 4% improvement for non-concurrent structures like >> ArrayList or LinkedHashSet, if we ignore the baseline difference (for >> Iterable). This is anticipated as the growth of array size is exponential, >> so the total

RFR: 8305785: Avoid redundant HashMap.containsKey call in java.util.regex

2023-04-09 Thread Andrey Turbanov
`Pattern.namedGroups` and `Matcher.namedGroups` contains only non-null values. It means instead of separate `containsKey`+`get` calls, we can use single `HashMap.get` call and then compare result with null. Result code is a bit simpler and faster. - Commit messages: - 8305785: Avoi

Re: Add String & Character ASCII case conversion methods

2023-04-09 Thread Glavo
Hi, We discussed this issue on this mailing list[1] earlier this year. I investigated the usage of these two methods and found that all use cases within JDK are suspicious, resulting in many imperceptible bugs. I hope to create a PR for this issue, deprecate these two methods, and create alterna

Add String & Character ASCII case conversion methods

2023-04-09 Thread some-java-user-99206970363698485155
Hello, could you please add String & Character ASCII case conversion methods, that is, methods which only perform case conversion on ASCII characters in the input and leave any other characters unchanged. The conversion should not depend on the default locale. For example: - String: - toAsciiL

Integrated: 8305696: (zipfs) Avoid redundant LinkedHashMap.containsKey call ZipFileSystem.makeParentDirs

2023-04-09 Thread Andrey Turbanov
On Mon, 3 Apr 2023 17:16:26 GMT, Andrey Turbanov wrote: > `LinkedHashMap` `ZipFileSystem.inodes` contains only > non-null values. It means instead of separate `containsKey`+`get` calls, we > can use single `LinkedHashMap.get` call and then compare result with `null`. > Result code is a bit simp

Re: RFR: 8305696: (zipfs) Avoid redundant LinkedHashMap.containsKey call ZipFileSystem.makeParentDirs

2023-04-09 Thread Andrey Turbanov
On Mon, 3 Apr 2023 17:16:26 GMT, Andrey Turbanov wrote: > `LinkedHashMap` `ZipFileSystem.inodes` contains only > non-null values. It means instead of separate `containsKey`+`get` calls, we > can use single `LinkedHashMap.get` call and then compare result with `null`. > Result code is a bit simp

Re: RFR: 8302819: Remove JAR Index [v6]

2023-04-09 Thread Eirik Bjorsnos
On Fri, 7 Apr 2023 07:47:49 GMT, Eirik Bjorsnos wrote: >> This PR removes the JAR index feature from the runtime: >> >> - `URLClassPath` is updated to remove the `enableJarIndex` system property >> and any code which would be called when this property was `true` >> - The `JarIndex` implementat

Re: RFR: 8305774: String.join(CharSequence, Iterable) can be optimized if Iterable is a Collection [v2]

2023-04-09 Thread ExE Boss
On Sun, 9 Apr 2023 02:28:37 GMT, Tingjun Yuan wrote: >> In the current implementation of `String.join(CharSequence, Iterable)`, the >> temp array `elems` is always initialized with a length of 8. It will cause >> many array recreations when the `Iterable` contains more than 8 elements. >> Furt