Optimized byte re-ordering

This commit is contained in:
Dylan K. Taylor 2016-11-29 11:48:01 +00:00
parent d70be232d8
commit dd01407dd4

View File

@ -691,12 +691,13 @@ class GenericChunk implements Chunk{
*/ */
public static final function reorderByteArray(string $array) : string{ public static final function reorderByteArray(string $array) : string{
$result = str_repeat("\x00", 4096); $result = str_repeat("\x00", 4096);
$i = 0;
for($x = 0; $x < 16; ++$x){ for($x = 0; $x < 16; ++$x){
for($z = 0; $z < 16; ++$z){ for($z = 0; $z < 256; $z += 16){
$xz = (($x << 8) | ($z << 4)); $zx = ($z + $x);
$zx = (($z << 4) | $x); for($y = 0; $y < 4096; $y += 256){
for($y = 0; $y < 16; ++$y){ $result{$i} = $array{$y + $zx};
$result{$xz | $y} = $array{($y << 8) | $zx}; ++$i;
} }
} }
} }