From 0fc12da00815b30f0f2122d46f1aad8d4e63658e Mon Sep 17 00:00:00 2001 From: Uriel Salischiker Date: Fri, 16 Apr 2021 14:44:12 +0200 Subject: [PATCH] Clone with correct size to avoid resizing --- src/main/java/net/querz/nbt/tag/CompoundTag.java | 2 +- src/main/java/net/querz/nbt/tag/ListTag.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/querz/nbt/tag/CompoundTag.java b/src/main/java/net/querz/nbt/tag/CompoundTag.java index 9cdc3363..6c754cd7 100644 --- a/src/main/java/net/querz/nbt/tag/CompoundTag.java +++ b/src/main/java/net/querz/nbt/tag/CompoundTag.java @@ -282,7 +282,7 @@ public int compareTo(CompoundTag o) { @Override public CompoundTag clone() { - CompoundTag copy = new CompoundTag(); + CompoundTag copy = new CompoundTag(((int) Math.ceil(getValue().size() * 1.75f)) + 1); for (Map.Entry> e : getValue().entrySet()) { copy.put(e.getKey(), e.getValue().clone()); } diff --git a/src/main/java/net/querz/nbt/tag/ListTag.java b/src/main/java/net/querz/nbt/tag/ListTag.java index 955ad1a4..6f381351 100644 --- a/src/main/java/net/querz/nbt/tag/ListTag.java +++ b/src/main/java/net/querz/nbt/tag/ListTag.java @@ -320,7 +320,7 @@ public int compareTo(ListTag o) { @SuppressWarnings("unchecked") @Override public ListTag clone() { - ListTag copy = new ListTag<>(this.size()); + ListTag copy = new ListTag<>(((int) Math.ceil(this.size() * 1.75)) + 1); // assure type safety for clone copy.typeClass = typeClass; for (T t : getValue()) {