BlockStateDictionary: slash another 14% off memory usage by deduplicating block type names

perhaps we could construct a dictionary from BlockTypeNames reflection??
This commit is contained in:
Dylan K. Taylor
2023-05-03 23:14:53 +01:00
parent ed021d193d
commit f9d9cbd0f6
2 changed files with 9 additions and 5 deletions

View File

@@ -130,6 +130,7 @@ final class BlockStateDictionary{
$entries = [];
$uniqueNames = [];
foreach(self::loadPaletteFromString($blockPaletteContents) as $i => $state){
$meta = $metaMap[$i] ?? null;
if($meta === null){
@@ -138,7 +139,8 @@ final class BlockStateDictionary{
if(!is_int($meta)){
throw new \InvalidArgumentException("Invalid metaMap offset $i, expected int, got " . get_debug_type($meta));
}
$entries[$i] = new BlockStateDictionaryEntry($state, $meta);
$uniqueName = $uniqueNames[$state->getName()] ??= $state->getName();
$entries[$i] = new BlockStateDictionaryEntry($uniqueName, $state->getStates(), $meta);
}
return new self($entries);