Re: RFR: 8324573: HashMap::putAll should resize to sum of both map sizes [v3]

2024-02-01 Thread jmehrens
On Sat, 27 Jan 2024 21:58:05 GMT, Joshua Cao wrote: >> src/java.base/share/classes/java/util/HashMap.java line 503: >> >>> 501: */ >>> 502: final void putMapEntries(Map m, boolean >>> evict) { >>> 503: int s = Math.max(size() + m.size(), m.size()); >> >> If we decide this appr

Re: RFR: 8324573: HashMap::putAll should resize to sum of both map sizes

2024-01-24 Thread jmehrens
On Wed, 24 Jan 2024 21:53:51 GMT, Hannes Greule wrote: >...then suggest we should change the Map::size() api to return a long... For any Map/Collection you can fetch the Spliterator and use estimateSize or getExactSizeIfKnown as both return size as a long. - PR Comment: https://gi

Re: RFR: 8322149: ConcurrentHashMap smarter presizing for copy constructor and putAll [v3]

2024-01-17 Thread jmehrens
On Wed, 17 Jan 2024 21:16:02 GMT, Joshua Cao wrote: >> ConcurrentHashMap's copy constructor calls `putAll()` -> `tryPresize()` -> >> `transfer()`. When coming from the copy constructor, the Map is empty, so >> there is nothing to transfer. But `transfer()` will still copy all the empty >> node

Re: RFR: 6356745: (coll) Add PriorityQueue(Collection, Comparator) [v6]

2024-01-04 Thread jmehrens
On Thu, 4 Jan 2024 14:21:54 GMT, Valeh Hajiyev wrote: > why do you think the code would avoid heapify? `initFromCollection` method > will be called regardless of the type of the collection passed, which will > heapify the queue. I simply mean to point out: 1. That if the given comparator and

Re: RFR: 6356745: (coll) Add PriorityQueue(Collection, Comparator) [v6]

2024-01-03 Thread jmehrens
On Sat, 30 Dec 2023 20:51:43 GMT, Chen Liang wrote: >I think this ticket should focus on adding the new constructor as part of the >API. Okay. I would think the code would avoid heapify when the caller does foolish things with this API such as: SortedSet ss = filledSortedSet(); PriorityQueue

Re: RFR: 6356745: (coll) Add PriorityQueue(Collection, Comparator) [v4]

2023-12-29 Thread jmehrens
On Mon, 25 Dec 2023 05:52:51 GMT, jmehrens wrote: >> Valeh Hajiyev has updated the pull request incrementally with one additional >> commit since the last revision: >> >> updated the javadoc > > Would adding a fast path to addAll solve this issue? I asked this

Re: RFR: 6356745: (coll) Add PriorityQueue(Collection, Comparator) [v4]

2023-12-24 Thread jmehrens
On Tue, 19 Dec 2023 21:17:02 GMT, Valeh Hajiyev wrote: >> This commit addresses the current limitation in the `PriorityQueue` >> implementation, which lacks a constructor to efficiently create a priority >> queue with a custom comparator and an existing collection. In order to >> create such a

Re: RFR: 8320971: Use BufferedInputStream.buf directly when param of implTransferTo() is trusted [v5]

2023-12-09 Thread jmehrens
On Sat, 9 Dec 2023 12:14:35 GMT, Bernd wrote: >> @stsypanov Yes but still it is just weird to ask any output stream if *it* >> is trusted. I mean, it feels just unsecure to ask: "Do *you* pretend to be >> trusted?" instead of "Do *we* trust you?". I could sleep better if this >> method would n

Re: RFR: 8320971: Use BufferedInputStream.buf directly when param of implTransferTo() is trusted [v3]

2023-12-01 Thread jmehrens
On Thu, 30 Nov 2023 11:12:36 GMT, Sergey Tsypanov wrote: >> It looks like we can skip copying of `byte[]` in >> `BufferedInputStream.implTransferTo()` for `OutputStreams` residing in >> `java.io`. >> >> See comment by @vlsi in >> https://github.com/openjdk/jdk/pull/10525/files#diff-e19c508d1b

Re: RFR: 8320971: Use BufferedInputStream.buf directly when param of implTransferTo() is trusted [v3]

2023-12-01 Thread jmehrens
On Thu, 30 Nov 2023 11:12:36 GMT, Sergey Tsypanov wrote: >> It looks like we can skip copying of `byte[]` in >> `BufferedInputStream.implTransferTo()` for `OutputStreams` residing in >> `java.io`. >> >> See comment by @vlsi in >> https://github.com/openjdk/jdk/pull/10525/files#diff-e19c508d1b

Re: RFR: 8321053: Use ByteArrayInputStream.buf directly when parameter of transferTo() is trusted [v2]

2023-12-01 Thread jmehrens
On Fri, 1 Dec 2023 23:21:35 GMT, Brian Burkhalter wrote: >> The case of `Channels.newOutputStream(AsynchronousByteChannel)` could be >> handled by changing the return value of that method. For example, >> `sun.nio.ch.Streams` could have a method `OutputStream >> of(AsynchronousByteChannel)` ad

Re: RFR: 8321053: Use ByteArrayInputStream.buf directly when parameter of transferTo() is trusted [v2]

2023-11-30 Thread jmehrens
On Fri, 1 Dec 2023 02:48:42 GMT, Brian Burkhalter wrote: >> The only other alternative would be to walk `((FilterOutputStream)out).out` >> and if everything in the out chain is in the "java." package then the out >> can be trusted. >> >> byte[] tmp = null; >> for (OutputStream os = out; os !=

Re: RFR: 8321053: Use ByteArrayInputStream.buf directly when parameter of transferTo() is trusted [v2]

2023-11-30 Thread jmehrens
On Thu, 30 Nov 2023 23:27:13 GMT, Brian Burkhalter wrote: >> Good catch: that in fact defeats the protection. > > Changed in 176d5165f7d8f3fa4814c9838abb5d18d9f3c338 not to trust > `FilterOutputStream`s. The only other alternative would be to walk `((FilterOutputStream)out).out` and if everyth

Re: RFR: 8320971: Use BufferedInputStream.buf directly when param of implTransferTo() is trusted

2023-11-29 Thread jmehrens
On Wed, 29 Nov 2023 22:38:59 GMT, Markus KARG wrote: >> src/java.base/share/classes/java/io/BufferedInputStream.java line 647: >> >>> 645: if (avail > 0) { >>> 646: // trust all OutputStreams from java.io >>> 647: if (out.getClass().getPackageName() ==

Re: RFR: 8321053: Use ByteArrayInputStream.buf directly when parameter of transferTo() is trusted

2023-11-29 Thread jmehrens
On Thu, 30 Nov 2023 00:03:21 GMT, Brian Burkhalter wrote: > Pass `ByteArrayInputStream.buf ` directly to the `OutputStream` parameter of > `BAIS.transferTo` only if the target stream is in the `java.io` package. src/java.base/share/classes/java/io/ByteArrayInputStream.java line 211: > 209:

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

2023-04-10 Thread jmehrens
On Mon, 10 Apr 2023 13:17:39 GMT, jmehrens wrote: >> Tingjun Yuan has updated the pull request incrementally with one additional >> commit since the last revision: >> >> use spliterator().estimateSize() > > src/java.base/share/classes/java/lang/Str

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

2023-04-10 Thread jmehrens
On Mon, 10 Apr 2023 05:46:23 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. >> Fur

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

2023-04-08 Thread jmehrens
On Fri, 7 Apr 2023 08:27:18 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. > Furtherm

Re: RFR: 8303923: ZipOutStream::putEntry should include an apiNote to indicate that the STORED compression method should be used when writing directory entries [v3]

2023-03-22 Thread jmehrens
On Sun, 19 Mar 2023 14:50:41 GMT, Eirik Bjorsnos wrote: >> ZipOutputStream currently writes directory entries using the DEFLATED >> compression method. This does not strictly comply with the APPNOTE.TXT >> specification and is also about 10x slower than using the STORED compression >> method.

Re: RFR: 8304245: Speed up CharacterData.of by avoiding bit shifting in the latin1 fast-path test [v2]

2023-03-18 Thread jmehrens
On Wed, 15 Mar 2023 15:10:49 GMT, Eirik Bjorsnos wrote: >> We can do `Integer.compareUnsigned(ch, 0xFF) <= 0` > > We could, but benchmarks show no performance improvements over the current > PR. I think the current code is perhaps slightly more readable. Does non-short-circuit logical AND opera

Re: RFR: 8294693: Add Collections.shuffle overload that accepts RandomGenerator interface [v3]

2022-10-31 Thread jmehrens
On Fri, 28 Oct 2022 23:18:00 GMT, Stuart Marks wrote: > I'm having difficulty imagining how SequencedCollection::replaceAll could > work or be useful. Obviously it's on List already. In Collections.java, it seems that the cases of AbstractSequentialList are handled like so: 1. Call toArray 2.

Re: RFR: 8294693: Add Collections.shuffle overload that accepts RandomGenerator interface [v3]

2022-10-17 Thread jmehrens
On Sat, 15 Oct 2022 07:30:54 GMT, Tagir F. Valeev wrote: > For unsorted sets like LinkedHashSet, it's unclear how to behave if > replaceAll returns identical elements. Throw an exception? Shrink the set > size via deduplication? I would assume the spec for replaceAll would be borrowed from Ma

Re: RFR: 8294693: Add Collections.shuffle overload that accepts RandomGenerator interface [v3]

2022-10-13 Thread jmehrens
On Wed, 12 Oct 2022 13:26:29 GMT, Tagir F. Valeev wrote: >> Java 17 added RandomGenerator interface. However, existing method >> Collections.shuffle accepts old java.util.Random class. While since Java 19, >> it's possible to use Random.from(RandomGenerator) wrapper, it would be more >> conven