On Mon, 9 Jan 2023 18:34:57 GMT, Per Minborg <[email protected]> wrote:

>> Viktor Klang has updated the pull request incrementally with two additional 
>> commits since the last revision:
>> 
>>  - 8299444: java.util.Set.copyOf allocates needlessly for empty input 
>> collections
>>    
>>        Modifies ImmutableCollections.listCopy:
>>        Introduces a check for isEmpty to avoid allocation in the case of an 
>> empty input collection.
>>  - 8299444: java.util.Set.copyOf allocates needlessly for empty input 
>> collections
>>    
>>    Modifies Map.copyOf:
>>    Introduces a check for isEmpty to avoid allocation in the case of an 
>> empty input Map.
>
> On the note of `CHM::isEmpty`: It would be better to rewrite this method as a 
> short-circuitable reduction of the many CounterCells' values. As soon as at 
> least one of them are >0 then the map is not empty. In contrast, today we sum 
> all of the values, in many cases, unnecessary.

@minborg Yes, I noted that when I looked into the current impl of CHM.isEmpty() 
as well. Seems like either a bespoke isEmpty implementation, or having 
isEmpty() rely on a more generalized "isLargerThan(0)" would be appropriate. 
With that said, I'm hesitant to make any modifications to CHM as a part of this 
PR :)

-------------

PR: https://git.openjdk.org/jdk/pull/11847

Reply via email to