62 lines
3.4 KiB
Diff
62 lines
3.4 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: IPECTER <ipectert@gmail.com>
|
|
Date: Wed, 10 May 2023 15:30:03 +0900
|
|
Subject: [PATCH] More-Optimise-State-Lookup
|
|
|
|
|
|
diff --git a/src/main/java/io/papermc/paper/util/table/ZeroCollidingReferenceStateTable.java b/src/main/java/io/papermc/paper/util/table/ZeroCollidingReferenceStateTable.java
|
|
index 57d0cd3ad6f972e986c72a57f1a6e36003f190c2..5c03e26db0f9da992e9b0487a872e0ec8786650a 100644
|
|
--- a/src/main/java/io/papermc/paper/util/table/ZeroCollidingReferenceStateTable.java
|
|
+++ b/src/main/java/io/papermc/paper/util/table/ZeroCollidingReferenceStateTable.java
|
|
@@ -16,7 +16,7 @@ public final class ZeroCollidingReferenceStateTable {
|
|
protected final Comparable<?>[] this_table;
|
|
protected final StateHolder<?, ?> this_state;
|
|
|
|
- protected long[] index_table;
|
|
+ protected long[] index_table; public long[] index_table() { return index_table; } // Plazma - Paper - optimise state lookup
|
|
protected StateHolder<?, ?>[][] value_table;
|
|
|
|
public ZeroCollidingReferenceStateTable(final StateHolder<?, ?> state, final Map<Property<?>, Comparable<?>> this_map) {
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/state/StateHolder.java b/src/main/java/net/minecraft/world/level/block/state/StateHolder.java
|
|
index 170f5cb3f01a57ad76e3bbeacd5b7c7e52f29959..ec42cafb7a9caf710f9ec5cea6130d54092dc5d2 100644
|
|
--- a/src/main/java/net/minecraft/world/level/block/state/StateHolder.java
|
|
+++ b/src/main/java/net/minecraft/world/level/block/state/StateHolder.java
|
|
@@ -114,21 +114,17 @@ public abstract class StateHolder<O, S> {
|
|
}
|
|
|
|
public <T extends Comparable<T>, V extends T> S trySetValue(Property<T> property, V value) {
|
|
- Comparable<?> comparable = this.values.get(property);
|
|
- if (comparable != null && comparable != value) {
|
|
- S object = this.neighbours.get(property, value);
|
|
- if (object == null) {
|
|
- throw new IllegalArgumentException("Cannot set property " + property + " to " + value + " on " + this.owner + ", it is not an allowed value");
|
|
- } else {
|
|
- return object;
|
|
- }
|
|
- } else {
|
|
- return (S)this;
|
|
+ // Plazma start - Paper - optimise state lookup
|
|
+ final S ret = (S)this.optimisedTable.get(property, value);
|
|
+ if (ret == null) {
|
|
+ throw new IllegalArgumentException("Cannot set property " + property + " to " + value + " on " + this.owner + ", it is not an allowed value");
|
|
}
|
|
+ return ret;
|
|
+ // Plazma end - Paper - optimise state lookup
|
|
}
|
|
|
|
public void populateNeighbours(Map<Map<Property<?>, Comparable<?>>, S> states) {
|
|
- if (this.neighbours != null) {
|
|
+ if (this.optimisedTable.index_table() != null) {
|
|
throw new IllegalStateException();
|
|
} else {
|
|
Table<Property<?>, Comparable<?>, S> table = HashBasedTable.create();
|
|
@@ -143,7 +139,7 @@ public abstract class StateHolder<O, S> {
|
|
}
|
|
}
|
|
|
|
- this.neighbours = (Table<Property<?>, Comparable<?>, S>)(table.isEmpty() ? table : ArrayTable.create(table)); this.optimisedTable.loadInTable((Table)this.neighbours, this.values); // Paper - optimise state lookup
|
|
+ this.optimisedTable.loadInTable((Table)(table.isEmpty() ? table : ArrayTable.create(table)), this.values); // Paper - optimise state lookup // Plazma
|
|
}
|
|
}
|
|
|