From dc9065285313aaeacc584e17bfa9f9487b1c7cde Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Thu, 19 Jul 2018 21:01:27 -0300 Subject: [PATCH] Memory efficiency --- .../chunks/ChunkSection1_13.java | 11 ++++++++--- .../protocol1_13to1_12_2/data/MappingData.java | 15 ++++++++++++++- .../chunks/ChunkSection1_9_3_4.java | 10 +++++++--- .../chunks/ChunkSection1_9_1_2.java | 10 +++++++--- .../chunks/ChunkSection1_9to1_8.java | 4 ++-- pom.xml | 2 +- 6 files changed, 39 insertions(+), 13 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/chunks/ChunkSection1_13.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/chunks/ChunkSection1_13.java index 736b6891f..4361e0d70 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/chunks/ChunkSection1_13.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/chunks/ChunkSection1_13.java @@ -135,7 +135,12 @@ public class ChunkSection1_13 implements ChunkSection { } // Read blocks - Long[] blockData = Type.LONG_ARRAY.read(input); + // Long[] blockData = Type.LONG_ARRAY.read(input); + long[] blockData = new long[Type.VAR_INT.read(input)]; + for (int i = 0; i < blockData.length; i++) { + blockData[i] = input.readLong(); + } + if (blockData.length > 0) { for (int i = 0; i < blocks.length; i++) { int bitIndex = i * bitsPerBlock; @@ -222,7 +227,7 @@ public class ChunkSection1_13 implements ChunkSection { } } for (long l : data) { - Type.LONG.write(output, l); + output.writeLong(l); } } @@ -265,7 +270,7 @@ public class ChunkSection1_13 implements ChunkSection { } } for (long l : data) { - Type.LONG.write(output, l); + output.writeLong(l); } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/MappingData.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/MappingData.java index c51cd40dc..b86c5db17 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/MappingData.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/data/MappingData.java @@ -5,6 +5,8 @@ import com.google.common.collect.HashBiMap; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import io.netty.util.collection.IntObjectHashMap; +import io.netty.util.collection.IntObjectMap; import us.myles.ViaVersion.util.GsonUtil; import java.io.IOException; @@ -14,7 +16,7 @@ import java.util.HashMap; import java.util.Map; public class MappingData { - public static Map oldToNewBlocks = new HashMap<>(); + public static IntObjectMap oldToNewBlocks = new IntObjectHashMap<>(); public static BiMap oldToNewItems = HashBiMap.create(); public static Map blockTags = new HashMap<>(); public static Map itemTags = new HashMap<>(); @@ -52,6 +54,17 @@ public class MappingData { } } + private static void mapIdentifiers(IntObjectMap output, JsonObject oldIdentifiers, JsonObject newIdentifiers) { + for (Map.Entry entry : oldIdentifiers.entrySet()) { + Map.Entry value = findValue(newIdentifiers, entry.getValue().getAsString()); + if (value == null) { + System.out.println("No key for " + entry.getValue() + " :( "); + continue; + } + output.put(Integer.parseInt(entry.getKey()), Integer.parseInt(value.getKey())); + } + } + private static Map.Entry findValue(JsonObject object, String needle) { for (Map.Entry entry : object.entrySet()) { String value = entry.getValue().getAsString(); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_1_2to1_9_3_4/chunks/ChunkSection1_9_3_4.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_1_2to1_9_3_4/chunks/ChunkSection1_9_3_4.java index 93e5bd0a6..8539f0f14 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_1_2to1_9_3_4/chunks/ChunkSection1_9_3_4.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_1_2to1_9_3_4/chunks/ChunkSection1_9_3_4.java @@ -153,7 +153,11 @@ public class ChunkSection1_9_3_4 implements ChunkSection { } // Read blocks - Long[] blockData = Type.LONG_ARRAY.read(input); + //Long[] blockData = Type.LONG_ARRAY.read(input); + long[] blockData = new long[Type.VAR_INT.read(input)]; + for (int i = 0; i < blockData.length; i++) { + blockData[i] = input.readLong(); + } if (blockData.length > 0) { for (int i = 0; i < blocks.length; i++) { int bitIndex = i * bitsPerBlock; @@ -245,7 +249,7 @@ public class ChunkSection1_9_3_4 implements ChunkSection { } } for (long l : data) { - Type.LONG.write(output, l); + output.writeLong(l); } } @@ -288,7 +292,7 @@ public class ChunkSection1_9_3_4 implements ChunkSection { } } for (long l : data) { - Type.LONG.write(output, l); + output.writeLong(l); } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/chunks/ChunkSection1_9_1_2.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/chunks/ChunkSection1_9_1_2.java index 03bede471..fff7980bd 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/chunks/ChunkSection1_9_1_2.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/chunks/ChunkSection1_9_1_2.java @@ -145,7 +145,11 @@ public class ChunkSection1_9_1_2 implements ChunkSection { } // Read blocks - Long[] blockData = Type.LONG_ARRAY.read(input); + // Long[] blockData = Type.LONG_ARRAY.read(input); + long[] blockData = new long[Type.VAR_INT.read(input)]; + for (int i = 0; i < blockData.length; i++) { + blockData[i] = input.readLong(); + } if (blockData.length > 0) { for (int i = 0; i < blocks.length; i++) { int bitIndex = i * bitsPerBlock; @@ -237,7 +241,7 @@ public class ChunkSection1_9_1_2 implements ChunkSection { } } for (long l : data) { - Type.LONG.write(output, l); + output.writeLong(l); } } @@ -280,7 +284,7 @@ public class ChunkSection1_9_1_2 implements ChunkSection { } } for (long l : data) { - Type.LONG.write(output, l); + output.writeLong(l); } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/chunks/ChunkSection1_9to1_8.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/chunks/ChunkSection1_9to1_8.java index 77ed52c0a..72a48578e 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/chunks/ChunkSection1_9to1_8.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/chunks/ChunkSection1_9to1_8.java @@ -144,7 +144,7 @@ public class ChunkSection1_9to1_8 implements ChunkSection { } } for (long l : data) { - Type.LONG.write(output, l); + output.writeLong(l); } } @@ -187,7 +187,7 @@ public class ChunkSection1_9to1_8 implements ChunkSection { } } for (long l : data) { - Type.LONG.write(output, l); + output.writeLong(l); } } diff --git a/pom.xml b/pom.xml index 8cc37e2db..91a1f9e2f 100644 --- a/pom.xml +++ b/pom.xml @@ -98,7 +98,7 @@ io.netty netty-all - 4.0.20.Final + 4.0.23.Final provided true