faster packet decode using pure-PHP functions instead of core-PHP ones :P. WTF PHP

This commit is contained in:
Shoghi Cervantes 2014-03-05 02:49:40 +01:00
parent 9c38ead76d
commit b00da18f41
3 changed files with 19 additions and 12 deletions

View File

@ -108,6 +108,7 @@ foreach($inc as $s){
$sha1sum ^= sha1_file($s, true);
}
/***REM_END***/
ini_set("opcache.mmap_base", bin2hex(Utils::getRandomBytes(8, false))); //Fix OPCache address errors
define("SOURCE_SHA1SUM", bin2hex($sha1sum));
/***REM_START***/

View File

@ -56,12 +56,15 @@ abstract class RakNetDataPacket extends stdClass{
if($len <= 0){
$this->offset = strlen($this->buffer) - 1;
return "";
}
if($len === true){
}elseif($len === true){
return substr($this->buffer, $this->offset);
}
$this->offset += $len;
return substr($this->buffer, $this->offset - $len, $len);
$buffer = b"";
for(; $len > 0; --$len, ++$this->offset){
$buffer .= $this->buffer{$this->offset};
}
return $buffer;
}
protected function put($str){
@ -118,7 +121,7 @@ abstract class RakNetDataPacket extends stdClass{
}
protected function getByte(){
return ord($this->get(1));
return ord($this->buffer{$this->offset++});
}
protected function putByte($v){

View File

@ -31,17 +31,20 @@ class RakNetPacket extends Packet{
public function pid(){
return $this->packetID;
}
private function get($len){
protected function get($len){
if($len <= 0){
$this->offset = strlen($this->buffer) - 1;
return "";
}
if($len === true){
}elseif($len === true){
return substr($this->buffer, $this->offset);
}
$this->offset += $len;
return substr($this->buffer, $this->offset - $len, $len);
$buffer = b"";
for(; $len > 0; --$len, ++$this->offset){
$buffer .= $this->buffer{$this->offset};
}
return $buffer;
}
private function getLong($unsigned = false){
@ -61,7 +64,7 @@ class RakNetPacket extends Packet{
}
private function getByte(){
return ord($this->get(1));
return ord($this->buffer{$this->offset++});
}
private function feof(){