Re: Optimization (?) of HashSet(Collection)

2021-10-15 Thread Andrew Haley
On 10/4/21 12:57, Сергей Цыпанов wrote: in the code of HashSet(Collection) we have an optimization opportunity: public HashSet(Collection c) { map = new HashMap<>(Math.max((int) (c.size()/.75f) + 1, 16)); addAll(c); } instead of using addAll() inherited from j.u.Collection we c

Optimization (?) of HashSet(Collection)

2021-10-04 Thread Сергей Цыпанов
Hello, in the code of HashSet(Collection) we have an optimization opportunity: public HashSet(Collection c) { map = new HashMap<>(Math.max((int) (c.size()/.75f) + 1, 16)); addAll(c); } instead of using addAll() inherited from j.u.Collection we can use c.forEach(this::add): public H