Remove unnecessary method call in PriorityBlockingQueue

Aleksei Ivanov alexey.ivanov at oracle.com
Wed May 24 18:03:19 UTC 2023


Hi Robin,

This belongs in core-libs.

On 24/05/2023 16:50, Robin Gong wrote:
> Hi,
>
> Recently, I found this constructor in PriorityBlockingQueue:
>
>       public PriorityBlockingQueue(int initialCapacity,
>                                      Comparator<? super E> comparator) {
>             if (initialCapacity < 1)
>                 throw new IllegalArgumentException();
>             this.comparator = comparator;
>             this.queue = new Object[Math.max(1, initialCapacity)];
>         }
>
>
> I believe we could change 'Math.max(1, initialCapacity)' to 
> 'initialCapacity'. Since initialCapacity must be greater or equal to 1.

It looks reasonable to me.

-- 
Regards,
Alexey

>
> And also that's how PriorityQueue running.
>
>       public PriorityQueue(int initialCapacity,
>                              Comparator<? super E> comparator) {
>             // Note: This restriction of at least one is not actually
>     needed,
>             // but continues for 1.5 compatibility
>             if (initialCapacity < 1)
>                 throw new IllegalArgumentException();
>             this.queue = new Object[initialCapacity];
>             this.comparator = comparator;
>         }
>
>
> Best regarts,
> Robin Gong
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/jdk-dev/attachments/20230524/c2cced67/attachment-0001.htm>


More information about the jdk-dev mailing list