Item: Improve performance of nbtSerialize() (#4831)

Replace hasNamedTag() with $nbt->count() > 0
This avoids a duplicate indirect call to Item::serializeCompoundTag() method call when serializing items with namedtags.
This commit is contained in:
Muqsit Rayyan
2022-02-16 05:32:12 +05:00
committed by GitHub
parent 55c744cc00
commit 55dfacea8d

View File

@ -659,8 +659,9 @@ class Item implements \JsonSerializable{
->setByte("Count", Binary::signByte($this->count)) ->setByte("Count", Binary::signByte($this->count))
->setShort("Damage", $this->getMeta()); ->setShort("Damage", $this->getMeta());
if($this->hasNamedTag()){ $tag = $this->getNamedTag();
$result->setTag("tag", $this->getNamedTag()); if($tag->count() > 0){
$result->setTag("tag", $tag);
} }
if($slot !== -1){ if($slot !== -1){