Added preprocessor optimizations

This commit is contained in:
Shoghi Cervantes
2014-10-30 07:58:53 +01:00
parent 8cb9dd9a14
commit d8f9def7f4
63 changed files with 163 additions and 35 deletions

View File

@ -228,24 +228,28 @@ class Binary{
}
/**
* Reads a 16-bit signed/unsigned big-endian number
* Reads a 16-bit unsigned big-endian number
*
* @param $str
* @param bool $signed
* @param $str
*
* @return int
*/
public static function readShort($str, $signed = true){
$unpacked = unpack("n", $str)[1];
public static function readShort($str){
return unpack("n", $str)[1];
}
if($signed){
if(PHP_INT_SIZE === 8){
return $unpacked << 48 >> 48;
}else{
return $unpacked << 16 >> 16;
}
/**
* Reads a 16-bit signed big-endian number
*
* @param $str
*
* @return int
*/
public static function readSignedShort($str){
if(PHP_INT_SIZE === 8){
return unpack("n", $str)[1] << 48 >> 48;
}else{
return $unpacked;
return unpack("n", $str)[1] << 16 >> 16;
}
}
@ -261,24 +265,28 @@ class Binary{
}
/**
* Reads a 16-bit signed/unsigned little-endian number
* Reads a 16-bit unsigned little-endian number
*
* @param $str
* @param bool $signed
*
* @return int
*/
public static function readLShort($str, $signed = true){
$unpacked = unpack("v", $str)[1];
public static function readLShort($str){
return unpack("v", $str)[1];
}
if($signed){
if(PHP_INT_SIZE === 8){
return $unpacked << 48 >> 48;
}else{
return $unpacked << 16 >> 16;
}
/**
* Reads a 16-bit signed little-endian number
*
* @param $str
*
* @return int
*/
public static function readSignedLShort($str){
if(PHP_INT_SIZE === 8){
return unpack("v", $str)[1] << 48 >> 48;
}else{
return $unpacked;
return unpack("v", $str)[1] << 16 >> 16;
}
}
@ -361,7 +369,7 @@ class Binary{
$value = "0";
for($i = 0; $i < 8; $i += 2){
$value = bcmul($value, "65536", 0);
$value = bcadd($value, self::readShort(substr($x, $i, 2), false), 0);
$value = bcadd($value, self::readShort(substr($x, $i, 2)), 0);
}
if(bccomp($value, "9223372036854775807") == 1){