BlockStateUpgradeSchema: avoid unnecessary property access and calculation

this was costing a surprisingly large 5-10% of the processing time for blockstate data.
This commit is contained in:
Dylan K. Taylor 2024-03-12 11:45:08 +00:00
parent ac8dbf8640
commit 8ec304e66e
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 11 additions and 7 deletions

View File

@ -64,20 +64,24 @@ final class BlockStateUpgradeSchema{
*/
public array $remappedStates = [];
public readonly int $versionId;
public function __construct(
public int $maxVersionMajor,
public int $maxVersionMinor,
public int $maxVersionPatch,
public int $maxVersionRevision,
public readonly int $maxVersionMajor,
public readonly int $maxVersionMinor,
public readonly int $maxVersionPatch,
public readonly int $maxVersionRevision,
private int $schemaId
){}
){
$this->versionId = ($this->maxVersionMajor << 24) | ($this->maxVersionMinor << 16) | ($this->maxVersionPatch << 8) | $this->maxVersionRevision;
}
/**
* @deprecated This is defined by Mojang, and therefore cannot be relied on. Use getSchemaId() instead for
* internal version management.
*/
public function getVersionId() : int{
return ($this->maxVersionMajor << 24) | ($this->maxVersionMinor << 16) | ($this->maxVersionPatch << 8) | $this->maxVersionRevision;
return $this->versionId;
}
public function getSchemaId() : int{ return $this->schemaId; }

View File

@ -62,7 +62,7 @@ final class BlockStateUpgrader{
$version = $blockStateData->getVersion();
$highestVersion = $version;
foreach($this->upgradeSchemas as $schema){
$resultVersion = $schema->getVersionId();
$resultVersion = $schema->versionId;
$highestVersion = max($highestVersion, $resultVersion);
if($version > $resultVersion){
//even if this is actually the same version, we have to apply it anyway because mojang are dumb and