Skip to content

Commit 5a6f546

Browse files
committed
Make LogicUtil#removeDuplicates more efficient
Prevents expansion costs of the unique element ArrayList by making its initial size the size of the input Collection. Signed-off-by: Ollie <o.dzineit@gmail.com>
1 parent 42727a2 commit 5a6f546

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/main/java/com/flowpowered/commons/LogicUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class LogicUtil {
3636
* @return the input collection
3737
*/
3838
public static <T extends Collection<?>> T removeDuplicates(T input) {
39-
List<Object> unique = new ArrayList<>();
39+
List<Object> unique = new ArrayList<>(input.size());
4040
for (Iterator<?> iter = input.iterator(); iter.hasNext(); ) {
4141
Object next = iter.next();
4242
if (unique.contains(next)) {

0 commit comments

Comments
 (0)