mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-01 17:01:56 +01:00
80dcb6c4a3
Mojang included some sanity checks on arguments passed to the BlockData. This code results in the Hash look up occuring twice per call, one to test if it exists and another to retrieve the result. This code should ideally never be hit, unless mojang released a bad build. We can discover bugs with this as furthur code that never expects a null would then NPE, so it would not result in hidden issues. This is super hot code, so removing those checks should give decent gains.
43 lines
No EOL
2.3 KiB
Diff
43 lines
No EOL
2.3 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Aikar <aikar@aikar.co>
|
|
Date: Fri, 18 Mar 2016 19:15:44 -0400
|
|
Subject: [PATCH] Optimize BlockStateList/BlockData
|
|
|
|
Mojang included some sanity checks on arguments passed to the BlockData.
|
|
This code results in the Hash look up occuring twice per call, one to test if it exists
|
|
and another to retrieve the result.
|
|
|
|
This code should ideally never be hit, unless mojang released a bad build. We can discover bugs with this as furthur code that never expects a null
|
|
would then NPE, so it would not result in hidden issues.
|
|
|
|
This is super hot code, so removing those checks should give decent gains.
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/BlockStateList.java b/src/main/java/net/minecraft/server/BlockStateList.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/server/BlockStateList.java
|
|
+++ b/src/main/java/net/minecraft/server/BlockStateList.java
|
|
@@ -0,0 +0,0 @@ public class BlockStateList {
|
|
}
|
|
|
|
public <T extends Comparable<T>> T get(IBlockState<T> iblockstate) {
|
|
- if (!this.b.containsKey(iblockstate)) {
|
|
- throw new IllegalArgumentException("Cannot get property " + iblockstate + " as it does not exist in " + this.a.t());
|
|
- } else {
|
|
- return iblockstate.b().cast(this.b.get(iblockstate));
|
|
- }
|
|
+ return iblockstate.b().cast(this.b.get(iblockstate)); // Paper
|
|
}
|
|
|
|
public <T extends Comparable<T>, V extends T> IBlockData set(IBlockState<T> iblockstate, V v0) {
|
|
- if (!this.b.containsKey(iblockstate)) {
|
|
- throw new IllegalArgumentException("Cannot set property " + iblockstate + " as it does not exist in " + this.a.t());
|
|
- } else if (!iblockstate.c().contains(v0)) {
|
|
- throw new IllegalArgumentException("Cannot set property " + iblockstate + " to " + v0 + " on block " + Block.REGISTRY.b(this.a) + ", it is not an allowed value");
|
|
- } else {
|
|
- return (IBlockData) (this.b.get(iblockstate) == v0 ? this : (IBlockData) this.c.get(iblockstate, v0));
|
|
- }
|
|
+ return this.b.get(iblockstate) == v0 ? this : this.c.get(iblockstate, v0); // Paper
|
|
}
|
|
|
|
public ImmutableMap<IBlockState<?>, Comparable<?>> s() {
|
|
--
|