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 <gpe@openrs2.org>
Graham 4 years ago
parent b3b46bee1a
commit f8835b7581
  1. 5
      cache/src/main/kotlin/org/openrs2/cache/Group.kt

@ -3,7 +3,6 @@ package org.openrs2.cache
import io.netty.buffer.ByteBuf import io.netty.buffer.ByteBuf
import it.unimi.dsi.fastutil.ints.Int2ObjectAVLTreeMap import it.unimi.dsi.fastutil.ints.Int2ObjectAVLTreeMap
import it.unimi.dsi.fastutil.ints.Int2ObjectSortedMap import it.unimi.dsi.fastutil.ints.Int2ObjectSortedMap
import it.unimi.dsi.fastutil.ints.Int2ObjectSortedMaps
import org.openrs2.buffer.use import org.openrs2.buffer.use
public object Group { public object Group {
@ -12,7 +11,9 @@ public object Group {
val singleEntry = group.singleOrNull() val singleEntry = group.singleOrNull()
if (singleEntry != null) { if (singleEntry != null) {
return Int2ObjectSortedMaps.singleton(singleEntry.id, input.retain()) val files = Int2ObjectAVLTreeMap<ByteBuf>()
files[singleEntry.id] = input.retain()
return files
} }
require(input.isReadable) require(input.isReadable)

Loading…
Cancel
Save