SubChunk: workaround opcache preloading constant issue

non-class constants aren't stored during preloading phase and for some reason they aren't pre-resolved in opcode arrays. However, they are resolved by value when referenced by class constants, and class constants stick, so we can use those instead.
This commit is contained in:
Dylan K. Taylor 2020-09-04 17:53:22 +01:00
parent f9c2ed6200
commit d2f1a3cf5b

View File

@ -38,6 +38,8 @@ if(!defined(__NAMESPACE__ . '\ZERO_NIBBLE_ARRAY')){
}
class SubChunk implements SubChunkInterface{
private const ZERO_NIBBLE_ARRAY = ZERO_NIBBLE_ARRAY;
/** @var string */
protected $ids;
/** @var string */
@ -68,7 +70,7 @@ class SubChunk implements SubChunkInterface{
substr_count($this->ids, "\x00") === 4096 and
(!$checkLight or (
substr_count($this->skyLight, "\xff") === 2048 and
$this->blockLight === ZERO_NIBBLE_ARRAY
$this->blockLight === self::ZERO_NIBBLE_ARRAY
))
);
}
@ -230,14 +232,14 @@ class SubChunk implements SubChunkInterface{
* reference to the const instead of duplicating the whole string. The string will only be duplicated when
* modified, which is perfect for this purpose.
*/
if($this->data === ZERO_NIBBLE_ARRAY){
$this->data = ZERO_NIBBLE_ARRAY;
if($this->data === self::ZERO_NIBBLE_ARRAY){
$this->data = self::ZERO_NIBBLE_ARRAY;
}
if($this->skyLight === ZERO_NIBBLE_ARRAY){
$this->skyLight = ZERO_NIBBLE_ARRAY;
if($this->skyLight === self::ZERO_NIBBLE_ARRAY){
$this->skyLight = self::ZERO_NIBBLE_ARRAY;
}
if($this->blockLight === ZERO_NIBBLE_ARRAY){
$this->blockLight = ZERO_NIBBLE_ARRAY;
if($this->blockLight === self::ZERO_NIBBLE_ARRAY){
$this->blockLight = self::ZERO_NIBBLE_ARRAY;
}
}
}