From 83fe761fe427905972e437e3865e6c45b760c3d8 Mon Sep 17 00:00:00 2001 From: Vrganj <43708436+Vrganj@users.noreply.github.com> Date: Thu, 9 May 2024 14:58:06 +0200 Subject: [PATCH] perf: Avoid expensive Plot#getOwner calls in Plot#getOwners (#4418) * Avoid expensive Plot#getOwner calls in Plot#getOwners * Don't check for the owner beforehand, because it's done in the loop regardless --- .../java/com/plotsquared/core/plot/Plot.java | 29 +++++-------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/plot/Plot.java b/Core/src/main/java/com/plotsquared/core/plot/Plot.java index 21ee3db05..91f6016b1 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/Plot.java +++ b/Core/src/main/java/com/plotsquared/core/plot/Plot.java @@ -643,35 +643,22 @@ public class Plot { } /** - * Gets a immutable set of owner UUIDs for a plot (supports multi-owner mega-plots). + * Gets an immutable set of owner UUIDs for a plot (supports multi-owner mega-plots). *

* This method cannot be used to add or remove owners from a plot. *

* - * @return Immutable view of plot owners + * @return Immutable set of plot owners */ public @NonNull Set getOwners() { - if (this.getOwner() == null) { - return ImmutableSet.of(); - } - if (isMerged()) { - Set plots = getConnectedPlots(); - Plot[] array = plots.toArray(new Plot[0]); - ImmutableSet.Builder owners = ImmutableSet.builder(); - UUID last = this.getOwner(); - owners.add(this.getOwner()); - for (final Plot current : array) { - if (current.getOwner() == null) { - continue; - } - if (last == null || current.getOwner().getMostSignificantBits() != last.getMostSignificantBits()) { - owners.add(current.getOwner()); - last = current.getOwner(); - } + ImmutableSet.Builder owners = ImmutableSet.builder(); + for (Plot plot : getConnectedPlots()) { + UUID owner = plot.getOwner(); + if (owner != null) { + owners.add(owner); } - return owners.build(); } - return ImmutableSet.of(this.getOwner()); + return owners.build(); } /**