Abuse property visibility to micro optimize CompoundTags

this produced a little less than 10% performance improvement under xdebug, and while the real-time benefit is negligible, it's harmless to have.
This commit is contained in:
Dylan K. Taylor 2017-10-20 20:07:54 +01:00
parent 55a1731da3
commit 554096953b

View File

@ -59,7 +59,7 @@ class CompoundTag extends NamedTag implements \ArrayAccess{
if(is_array($value)){ if(is_array($value)){
foreach($value as $name => $tag){ foreach($value as $name => $tag){
if($tag instanceof NamedTag){ if($tag instanceof NamedTag){
$this->{$tag->getName()} = $tag; $this->{$tag->__name} = $tag;
}else{ }else{
throw new \TypeError("CompoundTag members must be NamedTags, got " . gettype($tag) . " in given array"); throw new \TypeError("CompoundTag members must be NamedTags, got " . gettype($tag) . " in given array");
} }
@ -121,7 +121,7 @@ class CompoundTag extends NamedTag implements \ArrayAccess{
* @param NamedTag $tag * @param NamedTag $tag
*/ */
public function setTag(NamedTag $tag) : void{ public function setTag(NamedTag $tag) : void{
$this->{$tag->getName()} = $tag; $this->{$tag->__name} = $tag;
} }
/** /**
@ -400,8 +400,8 @@ class CompoundTag extends NamedTag implements \ArrayAccess{
$this->value = []; $this->value = [];
do{ do{
$tag = $nbt->readTag($network); $tag = $nbt->readTag($network);
if($tag instanceof NamedTag and $tag->getName() !== ""){ if($tag instanceof NamedTag and $tag->__name !== ""){
$this->{$tag->getName()} = $tag; $this->{$tag->__name} = $tag;
} }
}while(!($tag instanceof EndTag) and !$nbt->feof()); }while(!($tag instanceof EndTag) and !$nbt->feof());
} }