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
This commit is contained in:
Vrganj 2024-05-09 14:58:06 +02:00 committed by GitHub
parent a7447c9d75
commit 83fe761fe4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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).
* <p>
* This method cannot be used to add or remove owners from a plot.
* </p>
*
* @return Immutable view of plot owners
* @return Immutable set of plot owners
*/
public @NonNull Set<UUID> getOwners() {
if (this.getOwner() == null) {
return ImmutableSet.of();
}
if (isMerged()) {
Set<Plot> plots = getConnectedPlots();
Plot[] array = plots.toArray(new Plot[0]);
ImmutableSet.Builder<UUID> 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<UUID> 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();
}
/**