Re: [PATCH] Minor optimisation for Set.copyOf(Collection)

2018-06-22 Thread Andrej Golovnin
Hi Tagir, > What if it's TreeSet with custom comparator which may differentiate elements > equal by .equals()? Or, even simpler, Collections.newSetFromMap(new > IdentityHashMap<>())? In both cases Set.of(array) would throw. You are right. I haven't thought about this cases. OK, then we should at l

Re: [PATCH] Minor optimisation for Set.copyOf(Collection)

2018-06-22 Thread Tagir Valeev
Hello! What if it's TreeSet with custom comparator which may differentiate elements equal by .equals()? Or, even simpler, Collections.newSetFromMap(new IdentityHashMap<>())? In both cases Set.of(array) would throw. With best regards, Tagir Valeev. On Fri, Jun 22, 2018 at 4:43 PM Andrej Golovnin

Re: [PATCH] Minor optimisation for Set.copyOf(Collection)

2018-06-22 Thread Andrej Golovnin
> Hi all, > > the current implementation of Set.copyOf(Collection coll) > creates an intermediate HashSet object to remove duplicates even when > coll is already a Set. The attached patch adds an additional check > whether coll is already a Set and if yes, then calls #toArray() > directly on coll a

[PATCH] Minor optimisation for Set.copyOf(Collection)

2018-06-22 Thread Andrej Golovnin
Hi all, the current implementation of Set.copyOf(Collection coll) creates an intermediate HashSet object to remove duplicates even when coll is already a Set. The attached patch adds an additional check whether coll is already a Set and if yes, then calls #toArray() directly on coll and passes the