mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-10-05 01:57:28 +02:00
Abandon TreeSet in ApplicableRegionSet for performance reasons.
This commit is contained in:
parent
d43eb3bc34
commit
c43a24d78f
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package com.sk89q.worldguard.protection;
|
package com.sk89q.worldguard.protection;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.ObjectArrays;
|
import com.google.common.collect.ObjectArrays;
|
||||||
import com.sk89q.worldguard.LocalPlayer;
|
import com.sk89q.worldguard.LocalPlayer;
|
||||||
import com.sk89q.worldguard.protection.association.RegionAssociable;
|
import com.sk89q.worldguard.protection.association.RegionAssociable;
|
||||||
@ -35,9 +36,8 @@
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.SortedSet;
|
|
||||||
import java.util.TreeSet;
|
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.sk89q.worldguard.protection.flags.StateFlag.test;
|
import static com.sk89q.worldguard.protection.flags.StateFlag.test;
|
||||||
@ -56,7 +56,7 @@ public class ApplicableRegionSet implements Iterable<ProtectedRegion> {
|
|||||||
*/
|
*/
|
||||||
private static final ApplicableRegionSet EMPTY = new ApplicableRegionSet(Collections.<ProtectedRegion>emptyList(), null);
|
private static final ApplicableRegionSet EMPTY = new ApplicableRegionSet(Collections.<ProtectedRegion>emptyList(), null);
|
||||||
|
|
||||||
private final SortedSet<ProtectedRegion> applicable;
|
private final List<ProtectedRegion> applicable;
|
||||||
private final FlagValueCalculator flagValueCalculator;
|
private final FlagValueCalculator flagValueCalculator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -67,8 +67,8 @@ public class ApplicableRegionSet implements Iterable<ProtectedRegion> {
|
|||||||
* @param applicable the regions contained in this set
|
* @param applicable the regions contained in this set
|
||||||
* @param globalRegion the global region, set aside for special handling.
|
* @param globalRegion the global region, set aside for special handling.
|
||||||
*/
|
*/
|
||||||
public ApplicableRegionSet(Collection<ProtectedRegion> applicable, @Nullable ProtectedRegion globalRegion) {
|
public ApplicableRegionSet(List<ProtectedRegion> applicable, @Nullable ProtectedRegion globalRegion) {
|
||||||
this(new TreeSet<ProtectedRegion>(checkNotNull(applicable)), globalRegion);
|
this(applicable, globalRegion, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -76,9 +76,13 @@ public ApplicableRegionSet(Collection<ProtectedRegion> applicable, @Nullable Pro
|
|||||||
*
|
*
|
||||||
* @param applicable the regions contained in this set
|
* @param applicable the regions contained in this set
|
||||||
* @param globalRegion the global region, set aside for special handling.
|
* @param globalRegion the global region, set aside for special handling.
|
||||||
|
* @param sorted true if the list is already sorted
|
||||||
*/
|
*/
|
||||||
public ApplicableRegionSet(SortedSet<ProtectedRegion> applicable, @Nullable ProtectedRegion globalRegion) {
|
private ApplicableRegionSet(List<ProtectedRegion> applicable, @Nullable ProtectedRegion globalRegion, boolean sorted) {
|
||||||
checkNotNull(applicable);
|
checkNotNull(applicable);
|
||||||
|
if (!sorted) {
|
||||||
|
Collections.sort(applicable);
|
||||||
|
}
|
||||||
this.applicable = applicable;
|
this.applicable = applicable;
|
||||||
this.flagValueCalculator = new FlagValueCalculator(applicable, globalRegion);
|
this.flagValueCalculator = new FlagValueCalculator(applicable, globalRegion);
|
||||||
}
|
}
|
||||||
@ -342,7 +346,7 @@ public int size() {
|
|||||||
* @return a set of regions
|
* @return a set of regions
|
||||||
*/
|
*/
|
||||||
public Set<ProtectedRegion> getRegions() {
|
public Set<ProtectedRegion> getRegions() {
|
||||||
return Collections.unmodifiableSet(applicable);
|
return ImmutableSet.copyOf(applicable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -357,4 +361,16 @@ public static ApplicableRegionSet getEmpty() {
|
|||||||
return EMPTY;
|
return EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance using a list of regions that is known to
|
||||||
|
* already be sorted by priority descending.
|
||||||
|
*
|
||||||
|
* @param regions a list of regions
|
||||||
|
* @param globalRegion a global region
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static ApplicableRegionSet fromSortedList(List<ProtectedRegion> regions, @Nullable ProtectedRegion globalRegion) {
|
||||||
|
return new ApplicableRegionSet(regions, globalRegion, true);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -34,9 +34,9 @@
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.SortedSet;
|
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
@ -52,17 +52,17 @@
|
|||||||
*/
|
*/
|
||||||
public class FlagValueCalculator {
|
public class FlagValueCalculator {
|
||||||
|
|
||||||
private final SortedSet<ProtectedRegion> regions;
|
private final List<ProtectedRegion> regions;
|
||||||
@Nullable
|
@Nullable
|
||||||
private final ProtectedRegion globalRegion;
|
private final ProtectedRegion globalRegion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance.
|
* Create a new instance.
|
||||||
*
|
*
|
||||||
* @param regions a list of applicable regions
|
* @param regions a list of applicable regions that <strong>must be sorted by priority descending</strong>
|
||||||
* @param globalRegion an optional global region (null to not use one)
|
* @param globalRegion an optional global region (null to not use one)
|
||||||
*/
|
*/
|
||||||
public FlagValueCalculator(SortedSet<ProtectedRegion> regions, @Nullable ProtectedRegion globalRegion) {
|
public FlagValueCalculator(List<ProtectedRegion> regions, @Nullable ProtectedRegion globalRegion) {
|
||||||
checkNotNull(regions);
|
checkNotNull(regions);
|
||||||
|
|
||||||
this.regions = regions;
|
this.regions = regions;
|
||||||
|
@ -43,7 +43,6 @@
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
@ -289,7 +288,7 @@ public Set<ProtectedRegion> removeRegion(String id, RemovalStrategy strategy) {
|
|||||||
public ApplicableRegionSet getApplicableRegions(Vector position) {
|
public ApplicableRegionSet getApplicableRegions(Vector position) {
|
||||||
checkNotNull(position);
|
checkNotNull(position);
|
||||||
|
|
||||||
TreeSet<ProtectedRegion> regions = new TreeSet<ProtectedRegion>();
|
List<ProtectedRegion> regions = new ArrayList<ProtectedRegion>();
|
||||||
index.applyContaining(position, new RegionCollectionConsumer(regions, true));
|
index.applyContaining(position, new RegionCollectionConsumer(regions, true));
|
||||||
return new ApplicableRegionSet(regions, index.get("__global__"));
|
return new ApplicableRegionSet(regions, index.get("__global__"));
|
||||||
}
|
}
|
||||||
@ -304,7 +303,7 @@ public ApplicableRegionSet getApplicableRegions(Vector position) {
|
|||||||
public ApplicableRegionSet getApplicableRegions(ProtectedRegion region) {
|
public ApplicableRegionSet getApplicableRegions(ProtectedRegion region) {
|
||||||
checkNotNull(region);
|
checkNotNull(region);
|
||||||
|
|
||||||
TreeSet<ProtectedRegion> regions = new TreeSet<ProtectedRegion>();
|
List<ProtectedRegion> regions = new ArrayList<ProtectedRegion>();
|
||||||
index.applyIntersecting(region, new RegionCollectionConsumer(regions, true));
|
index.applyIntersecting(region, new RegionCollectionConsumer(regions, true));
|
||||||
return new ApplicableRegionSet(regions, index.get("__global__"));
|
return new ApplicableRegionSet(regions, index.get("__global__"));
|
||||||
}
|
}
|
||||||
|
@ -294,6 +294,7 @@ public void run() {
|
|||||||
position.multiply(16).toVector(0).toBlockVector(),
|
position.multiply(16).toVector(0).toBlockVector(),
|
||||||
position.add(1, 1).multiply(16).toVector(Integer.MAX_VALUE).toBlockVector());
|
position.add(1, 1).multiply(16).toVector(Integer.MAX_VALUE).toBlockVector());
|
||||||
index.applyIntersecting(chunkRegion, new RegionCollectionConsumer(regions, false));
|
index.applyIntersecting(chunkRegion, new RegionCollectionConsumer(regions, false));
|
||||||
|
Collections.sort(regions);
|
||||||
|
|
||||||
state.setRegions(Collections.unmodifiableList(regions));
|
state.setRegions(Collections.unmodifiableList(regions));
|
||||||
|
|
||||||
|
@ -26,12 +26,13 @@
|
|||||||
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.TreeSet;
|
import java.util.List;
|
||||||
|
|
||||||
public class MockApplicableRegionSet {
|
public class MockApplicableRegionSet {
|
||||||
|
|
||||||
private TreeSet<ProtectedRegion> regions = new TreeSet<ProtectedRegion>();
|
private List<ProtectedRegion> regions = new ArrayList<ProtectedRegion>();
|
||||||
private ProtectedRegion global;
|
private ProtectedRegion global;
|
||||||
private int id = 0;
|
private int id = 0;
|
||||||
private int playerIndex = 0;
|
private int playerIndex = 0;
|
||||||
@ -85,6 +86,7 @@ public ApplicableRegionSet getApplicableSet() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public FlagValueCalculator getFlagCalculator() {
|
public FlagValueCalculator getFlagCalculator() {
|
||||||
|
Collections.sort(regions);
|
||||||
return new FlagValueCalculator(regions, global);
|
return new FlagValueCalculator(regions, global);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user