119 lines
5.3 KiB
Diff
119 lines
5.3 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Sotr <i@omc.hk>
|
|
Date: Wed, 15 Apr 2020 04:28:25 +0700
|
|
Subject: [PATCH] Cache hashcode for BlockPosition
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/BaseBlockPosition.java b/src/main/java/net/minecraft/server/BaseBlockPosition.java
|
|
index e811295b4d6afcd920f60e0ce5440e43300d9085..5b39fca67855e9d7b266ef496330c2d16c1caced 100644
|
|
--- a/src/main/java/net/minecraft/server/BaseBlockPosition.java
|
|
+++ b/src/main/java/net/minecraft/server/BaseBlockPosition.java
|
|
@@ -2,8 +2,9 @@ package net.minecraft.server;
|
|
|
|
import com.google.common.base.MoreObjects;
|
|
import com.mojang.serialization.Codec;
|
|
-import java.util.stream.IntStream;
|
|
+
|
|
import javax.annotation.concurrent.Immutable;
|
|
+import java.util.stream.IntStream;
|
|
|
|
@Immutable
|
|
public class BaseBlockPosition implements Comparable<BaseBlockPosition> {
|
|
@@ -28,6 +29,7 @@ public class BaseBlockPosition implements Comparable<BaseBlockPosition> {
|
|
return b < 0 || b >= 256;
|
|
}
|
|
// Paper end
|
|
+ protected int hash; // Akarin - cache hashcode
|
|
|
|
public BaseBlockPosition(int i, int j, int k) {
|
|
this.a = i;
|
|
@@ -52,8 +54,20 @@ public class BaseBlockPosition implements Comparable<BaseBlockPosition> {
|
|
}
|
|
|
|
public final int hashCode() { // Paper
|
|
- return (this.getY() + this.getZ() * 31) * 31 + this.getX();
|
|
+ // Akarin start - cache hashcode
|
|
+ int result = hash; // Make the situation not too bad when it is modified by multiple threads
|
|
+ if (result == 0) {
|
|
+ result = (this.getY() + this.getZ() * 31) * 31 + this.getX(); // Paper
|
|
+ hash = result;
|
|
+ }
|
|
+ return result;
|
|
+ // return (this.getY() + this.getZ() * 31) * 31 + this.getX();
|
|
+ }
|
|
+
|
|
+ public final void recalcHashCode() {
|
|
+ hash = 0;
|
|
}
|
|
+ // Akarin end
|
|
|
|
public int compareTo(BaseBlockPosition baseblockposition) {
|
|
return this.getY() == baseblockposition.getY() ? (this.getZ() == baseblockposition.getZ() ? this.getX() - baseblockposition.getX() : this.getZ() - baseblockposition.getZ()) : this.getY() - baseblockposition.getY();
|
|
diff --git a/src/main/java/net/minecraft/server/BlockPosition.java b/src/main/java/net/minecraft/server/BlockPosition.java
|
|
index 2291135eaef64c403183724cb6e413cd7e472672..c1bd8e558963169d0adc3c0a7d6cfec19e1d1c98 100644
|
|
--- a/src/main/java/net/minecraft/server/BlockPosition.java
|
|
+++ b/src/main/java/net/minecraft/server/BlockPosition.java
|
|
@@ -453,6 +453,7 @@ public class BlockPosition extends BaseBlockPosition {
|
|
((BaseBlockPosition)this).a = i; // Tuinity - force inline
|
|
((BaseBlockPosition)this).b = j; // Tuinity - force inline
|
|
((BaseBlockPosition)this).e = k; // Tuinity - force inline
|
|
+ this.recalcHashCode(); // Akarin - cache hashcode
|
|
return this;
|
|
}
|
|
|
|
@@ -466,6 +467,7 @@ public class BlockPosition extends BaseBlockPosition {
|
|
((BaseBlockPosition)this).a = baseblockposition.a; // Tuinity - force inline
|
|
((BaseBlockPosition)this).b = baseblockposition.b; // Tuinity - force inline
|
|
((BaseBlockPosition)this).e = baseblockposition.e; // Tuinity - force inline
|
|
+ this.recalcHashCode(); // Akarin - cache hashcode
|
|
return this;
|
|
}
|
|
|
|
@@ -473,6 +475,7 @@ public class BlockPosition extends BaseBlockPosition {
|
|
((BaseBlockPosition)this).a = (int)(i >> 38); // Tuinity - force inline
|
|
((BaseBlockPosition)this).b = (int)((i << 52) >> 52); // Tuinity - force inline
|
|
((BaseBlockPosition)this).e = (int)((i << 26) >> 38); // Tuinity - force inline
|
|
+ this.recalcHashCode(); // Akarin - cache hashcode
|
|
return this;
|
|
}
|
|
|
|
@@ -492,6 +495,7 @@ public class BlockPosition extends BaseBlockPosition {
|
|
((BaseBlockPosition)this).a += enumdirection.getAdjacentX(); // Tuinity - force inline
|
|
((BaseBlockPosition)this).b += enumdirection.getAdjacentY(); // Tuinity - force inline
|
|
((BaseBlockPosition)this).e += enumdirection.getAdjacentZ(); // Tuinity - force inline
|
|
+ this.recalcHashCode(); // Akarin - cache hashcode
|
|
return this;
|
|
}
|
|
|
|
@@ -524,24 +528,30 @@ public class BlockPosition extends BaseBlockPosition {
|
|
// only expose set on the mutable blockpos
|
|
public final void setX(int value) {
|
|
((BaseBlockPosition)this).a = value;
|
|
+ this.recalcHashCode(); // Akarin - cache hashcode
|
|
}
|
|
public final void setY(int value) {
|
|
((BaseBlockPosition)this).b = value;
|
|
+ this.recalcHashCode(); // Akarin - cache hashcode
|
|
}
|
|
public final void setZ(int value) {
|
|
((BaseBlockPosition)this).e = value;
|
|
+ this.recalcHashCode(); // Akarin - cache hashcode
|
|
}
|
|
|
|
public final void o(int i) {
|
|
((BaseBlockPosition)this).a = i; // need cast thanks to name conflict
|
|
+ this.recalcHashCode(); // Akarin - cache hashcode
|
|
}
|
|
|
|
public final void p(int i) {
|
|
((BaseBlockPosition)this).b = i;
|
|
+ this.recalcHashCode(); // Akarin - cache hashcode
|
|
}
|
|
|
|
public final void q(int i) {
|
|
((BaseBlockPosition)this).e = i;
|
|
+ this.recalcHashCode(); // Akarin - cache hashcode
|
|
}
|
|
// Tuinity end
|
|
|