From 16dbbe5244dbbc7637b7f7aaac862600e059abc2 Mon Sep 17 00:00:00 2001 From: sauilitired Date: Wed, 14 Nov 2018 13:52:09 +0100 Subject: [PATCH] Refactoring of PS#getPlots: Initialize to HashSet rather than ArrayList, because of add in HashSet is O(1) vs. add in ArrayList which is O(n). Also make the wrapping set immutable. --- .../intellectualsites/plotsquared/plot/PS.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PS.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PS.java index cc2cb0ea1..59705e674 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PS.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PS.java @@ -966,18 +966,16 @@ public class PS { * * @param area the {@code PlotArea} * @param uuid the plot owner - * @return Set of plot + * @return Set of plots */ public Set getPlots(PlotArea area, UUID uuid) { - ArrayList myplots = new ArrayList<>(); + final HashSet plots = new HashSet<>(); for (Plot plot : getPlots(area)) { - if (plot.hasOwner()) { - if (plot.isOwnerAbs(uuid)) { - myplots.add(plot); - } + if (plot.hasOwner() && plot.isOwnerAbs(uuid)) { + plots.add(plot); } } - return new HashSet<>(myplots); + return Collections.unmodifiableSet(plots); } /**