mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2025-01-01 05:58:06 +01:00
Optimize the query cache a bit.
This commit is contained in:
parent
3ca147e405
commit
d43eb3bc34
@ -37,7 +37,7 @@
|
|||||||
*/
|
*/
|
||||||
class QueryCache {
|
class QueryCache {
|
||||||
|
|
||||||
private final ConcurrentMap<CacheKey, ApplicableRegionSet> cache = new ConcurrentHashMap<CacheKey, ApplicableRegionSet>();
|
private final ConcurrentMap<CacheKey, ApplicableRegionSet> cache = new ConcurrentHashMap<CacheKey, ApplicableRegionSet>(16, 0.75f, 2);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get from the cache a {@code ApplicableRegionSet} if an entry exists;
|
* Get from the cache a {@code ApplicableRegionSet} if an entry exists;
|
||||||
@ -76,12 +76,20 @@ private static class CacheKey {
|
|||||||
private final int x;
|
private final int x;
|
||||||
private final int y;
|
private final int y;
|
||||||
private final int z;
|
private final int z;
|
||||||
|
private final int hashCode;
|
||||||
|
|
||||||
private CacheKey(Location location) {
|
private CacheKey(Location location) {
|
||||||
this.world = location.getWorld();
|
this.world = location.getWorld();
|
||||||
this.x = location.getBlockX();
|
this.x = location.getBlockX();
|
||||||
this.y = location.getBlockY();
|
this.y = location.getBlockY();
|
||||||
this.z = location.getBlockZ();
|
this.z = location.getBlockZ();
|
||||||
|
|
||||||
|
// Pre-compute hash code
|
||||||
|
int result = world.hashCode();
|
||||||
|
result = 31 * result + x;
|
||||||
|
result = 31 * result + y;
|
||||||
|
result = 31 * result + z;
|
||||||
|
this.hashCode = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -101,11 +109,7 @@ public boolean equals(Object o) {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = world.hashCode();
|
return hashCode;
|
||||||
result = 31 * result + x;
|
|
||||||
result = 31 * result + y;
|
|
||||||
result = 31 * result + z;
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user