Unnecessary TagHandlerImpl getters

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2022-07-28 13:57:13 +02:00
parent 0db5993bfb
commit 614559bcdb

View File

@ -65,7 +65,7 @@ final class TagHandlerImpl implements TagHandler {
StaticIntMap<Entry<?>> entries = node.entries; StaticIntMap<Entry<?>> entries = node.entries;
if (value != null) { if (value != null) {
Entry previous = entries.get(tagIndex); Entry previous = entries.get(tagIndex);
if (previous != null && previous.tag().shareValue(tag)) { if (previous != null && previous.tag.shareValue(tag)) {
previous.updateValue(tag.copyValue(value)); previous.updateValue(tag.copyValue(value));
} else { } else {
synchronized (this) { synchronized (this) {
@ -104,7 +104,7 @@ final class TagHandlerImpl implements TagHandler {
StaticIntMap<Entry<?>> entries = node.entries; StaticIntMap<Entry<?>> entries = node.entries;
final Entry previousEntry = entries.get(tagIndex); final Entry previousEntry = entries.get(tagIndex);
final T previousValue = previousEntry != null ? (T) previousEntry.value() : tag.createDefault(); final T previousValue = previousEntry != null ? (T) previousEntry.value : tag.createDefault();
final T newValue = value.apply(previousValue); final T newValue = value.apply(previousValue);
if (newValue != null) entries.put(tagIndex, valueToEntry(node, tag, newValue)); if (newValue != null) entries.put(tagIndex, valueToEntry(node, tag, newValue));
else entries.remove(tagIndex); else entries.remove(tagIndex);
@ -181,7 +181,7 @@ final class TagHandlerImpl implements TagHandler {
// Slow path is taken if the entry comes from a Structure tag, requiring conversion from NBT // Slow path is taken if the entry comes from a Structure tag, requiring conversion from NBT
Node tmp = local; Node tmp = local;
local = new Node(tmp); local = new Node(tmp);
if (synEntry != null && synEntry.nbt() instanceof NBTCompound compound) { if (synEntry != null && synEntry.updatedNbt() instanceof NBTCompound compound) {
local.updateContent(compound); local.updateContent(compound);
} }
tmp.entries.put(pathIndex, Entry.makePathEntry(path.name(), local)); tmp.entries.put(pathIndex, Entry.makePathEntry(path.name(), local));
@ -234,14 +234,14 @@ final class TagHandlerImpl implements TagHandler {
final Entry<?> entry = entries.get(tag.index); final Entry<?> entry = entries.get(tag.index);
if (entry == null) if (entry == null)
return tag.createDefault(); // Not present return tag.createDefault(); // Not present
if (entry.tag().shareValue(tag)) { if (entry.tag.shareValue(tag)) {
// The tag used to write the entry is compatible with the one used to get // The tag used to write the entry is compatible with the one used to get
// return the value directly // return the value directly
//noinspection unchecked //noinspection unchecked
return (T) entry.value(); return (T) entry.value;
} }
// Value must be parsed from nbt if the tag is different // Value must be parsed from nbt if the tag is different
final NBT nbt = entry.nbt(); final NBT nbt = entry.updatedNbt();
final Serializers.Entry<T, NBT> serializerEntry = tag.entry; final Serializers.Entry<T, NBT> serializerEntry = tag.entry;
final NBTType<NBT> type = serializerEntry.nbtType(); final NBTType<NBT> type = serializerEntry.nbtType();
return type == null || type == nbt.getID() ? serializerEntry.read(nbt) : tag.createDefault(); return type == null || type == nbt.getID() ? serializerEntry.read(nbt) : tag.createDefault();
@ -259,8 +259,8 @@ final class TagHandlerImpl implements TagHandler {
if (!CACHE_ENABLE || (compound = this.compound) == null) { if (!CACHE_ENABLE || (compound = this.compound) == null) {
MutableNBTCompound tmp = new MutableNBTCompound(); MutableNBTCompound tmp = new MutableNBTCompound();
this.entries.forValues(entry -> { this.entries.forValues(entry -> {
final Tag tag = entry.tag(); final Tag tag = entry.tag;
final NBT nbt = entry.nbt(); final NBT nbt = entry.updatedNbt();
if (!tag.entry.isPath() || !((NBTCompound) nbt).isEmpty()) { if (!tag.entry.isPath() || !((NBTCompound) nbt).isEmpty()) {
tmp.put(tag.getKey(), nbt); tmp.put(tag.getKey(), nbt);
} }
@ -287,7 +287,7 @@ final class TagHandlerImpl implements TagHandler {
nbt = copy.compound; nbt = copy.compound;
assert nbt != null : "Node copy should also compute the compound"; assert nbt != null : "Node copy should also compute the compound";
} else { } else {
nbt = entry.nbt(); nbt = entry.updatedNbt();
} }
tmp.put(tag.getKey(), nbt); tmp.put(tag.getKey(), nbt);
@ -325,22 +325,14 @@ final class TagHandlerImpl implements TagHandler {
return makePathEntry(tag.getKey(), node); return makePathEntry(tag.getKey(), node);
} }
public Tag<T> tag() { NBT updatedNbt() {
return tag;
}
public T value() {
return value;
}
public NBT nbt() {
if (tag.entry.isPath()) return ((Node) value).compound(); if (tag.entry.isPath()) return ((Node) value).compound();
NBT nbt = this.nbt; NBT nbt = this.nbt;
if (nbt == null) this.nbt = nbt = tag.entry.write(value); if (nbt == null) this.nbt = nbt = tag.entry.write(value);
return nbt; return nbt;
} }
public void updateValue(T value) { void updateValue(T value) {
assert !tag.entry.isPath(); assert !tag.entry.isPath();
this.value = value; this.value = value;
this.nbt = null; this.nbt = null;
@ -348,7 +340,7 @@ final class TagHandlerImpl implements TagHandler {
Node toNode() { Node toNode() {
if (tag.entry.isPath()) return (Node) value; if (tag.entry.isPath()) return (Node) value;
if (nbt() instanceof NBTCompound compound) { if (updatedNbt() instanceof NBTCompound compound) {
// Slow path forcing a conversion of the structure to NBTCompound // Slow path forcing a conversion of the structure to NBTCompound
// TODO should the handler be cached inside the entry? // TODO should the handler be cached inside the entry?
return fromCompound(compound).root; return fromCompound(compound).root;