From f8835b7581ce34e2d029c37e2e8909b7b6b9c628 Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 23 Jan 2021 13:26:44 +0000 Subject: [PATCH] Always return a mutable Int2ObjectSortedMap from Group.unpack() Originally I used a singleton map if possible, to reduce overhead in the common case of a group containing a single file. However, the work-in-progress Cache class needs to mutate the map. Eventually my plan is to replace the Int2ObjectSortedMaps in Js5Index and Group with arrays, solving both the overhead and mutation problems. Signed-off-by: Graham --- cache/src/main/kotlin/org/openrs2/cache/Group.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cache/src/main/kotlin/org/openrs2/cache/Group.kt b/cache/src/main/kotlin/org/openrs2/cache/Group.kt index 7aa923cc..ff1cb44f 100644 --- a/cache/src/main/kotlin/org/openrs2/cache/Group.kt +++ b/cache/src/main/kotlin/org/openrs2/cache/Group.kt @@ -3,7 +3,6 @@ package org.openrs2.cache import io.netty.buffer.ByteBuf import it.unimi.dsi.fastutil.ints.Int2ObjectAVLTreeMap import it.unimi.dsi.fastutil.ints.Int2ObjectSortedMap -import it.unimi.dsi.fastutil.ints.Int2ObjectSortedMaps import org.openrs2.buffer.use public object Group { @@ -12,7 +11,9 @@ public object Group { val singleEntry = group.singleOrNull() if (singleEntry != null) { - return Int2ObjectSortedMaps.singleton(singleEntry.id, input.retain()) + val files = Int2ObjectAVLTreeMap() + files[singleEntry.id] = input.retain() + return files } require(input.isReadable)