BlockStateDictionary: added a smelly hack that saves another 40 KB

this is really diminishing returns at this point...
This commit is contained in:
Dylan K. Taylor 2023-05-03 23:18:06 +01:00
parent f9d9cbd0f6
commit 43fe819862
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\network\mcpe\convert;
use pocketmine\data\bedrock\block\BlockStateData;
use pocketmine\data\bedrock\block\BlockTypeNames;
use pocketmine\nbt\NbtDataException;
use pocketmine\nbt\TreeRoot;
use pocketmine\network\mcpe\protocol\serializer\NetworkNbtSerializer;
@ -31,6 +32,7 @@ use function array_map;
use function get_debug_type;
use function is_array;
use function is_int;
use function is_string;
use function json_decode;
use const JSON_THROW_ON_ERROR;
@ -131,6 +133,15 @@ final class BlockStateDictionary{
$entries = [];
$uniqueNames = [];
//this hack allows the internal cache index to use interned strings which are already available in the
//core code anyway, saving around 40 KB of memory
foreach((new \ReflectionClass(BlockTypeNames::class))->getConstants() as $value){
if(is_string($value)){
$uniqueNames[$value] = $value;
}
}
foreach(self::loadPaletteFromString($blockPaletteContents) as $i => $state){
$meta = $metaMap[$i] ?? null;
if($meta === null){