BlockStateDictionaryEntry: deduplicate encoded states

this saves about 500 KB of memory at no cost.
This commit is contained in:
Dylan K. Taylor 2023-05-04 16:14:41 +01:00
parent 897ba9f2d9
commit f1417e8dc9
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -33,6 +33,11 @@ use function ksort;
use const SORT_STRING;
final class BlockStateDictionaryEntry{
/**
* @var string[]
* @phpstan-var array<string, string>
*/
private static array $uniqueRawStates = [];
private string $rawStateProperties;
@ -44,7 +49,8 @@ final class BlockStateDictionaryEntry{
array $stateProperties,
private int $meta
){
$this->rawStateProperties = self::encodeStateProperties($stateProperties);
$rawStateProperties = self::encodeStateProperties($stateProperties);
$this->rawStateProperties = self::$uniqueRawStates[$rawStateProperties] ??= $rawStateProperties;
}
public function getStateName() : string{ return $this->stateName; }