mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 12:18:46 +00:00
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:
parent
ed021d193d
commit
f9d9cbd0f6
@ -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);
|
||||
|
@ -34,15 +34,17 @@ use const SORT_STRING;
|
||||
|
||||
final class BlockStateDictionaryEntry{
|
||||
|
||||
private string $stateName;
|
||||
private string $rawStateProperties;
|
||||
|
||||
/**
|
||||
* @param Tag[] $stateProperties
|
||||
*/
|
||||
public function __construct(
|
||||
BlockStateData $stateData,
|
||||
private string $stateName,
|
||||
array $stateProperties,
|
||||
private int $meta
|
||||
){
|
||||
$this->stateName = $stateData->getName();
|
||||
$this->rawStateProperties = self::encodeStateProperties($stateData->getStates());
|
||||
$this->rawStateProperties = self::encodeStateProperties($stateProperties);
|
||||
}
|
||||
|
||||
public function getStateName() : string{ return $this->stateName; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user