[WebSocket] Performance
Added unit tests for Rsv bit checks Using binary operators to check bits resulting in massive performance gains
This commit is contained in:
parent
59725ebc2d
commit
22c0ea19d9
@ -15,7 +15,7 @@ interface FrameInterface extends DataInterface {
|
|||||||
function isFinal();
|
function isFinal();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Was the payload masked?
|
* Is the payload masked?
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function isMasked();
|
function isMasked();
|
||||||
|
@ -127,9 +127,7 @@ class Frame implements FrameInterface {
|
|||||||
throw new \UnderflowException('Not enough bytes received to determine if this is the final frame in message');
|
throw new \UnderflowException('Not enough bytes received to determine if this is the final frame in message');
|
||||||
}
|
}
|
||||||
|
|
||||||
$fbb = sprintf('%08b', ord(substr($this->data, 0, 1)));
|
return 128 === (ord($this->data[0]) & 128);
|
||||||
|
|
||||||
return (boolean)(int)$fbb[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -141,9 +139,7 @@ class Frame implements FrameInterface {
|
|||||||
throw new \UnderflowException('Not enough bytes received to determine reserved bit');
|
throw new \UnderflowException('Not enough bytes received to determine reserved bit');
|
||||||
}
|
}
|
||||||
|
|
||||||
$fbb = sprintf('%08b', ord(substr($this->data, 0, 1)));
|
return 64 === (ord($this->data[0]) & 64);
|
||||||
|
|
||||||
return (boolean)(int)$fbb[1];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -155,9 +151,7 @@ class Frame implements FrameInterface {
|
|||||||
throw new \UnderflowException('Not enough bytes received to determine reserved bit');
|
throw new \UnderflowException('Not enough bytes received to determine reserved bit');
|
||||||
}
|
}
|
||||||
|
|
||||||
$fbb = sprintf('%08b', ord(substr($this->data, 0, 1)));
|
return 32 === (ord($this->data[0]) & 32);
|
||||||
|
|
||||||
return (boolean)(int)$fbb[2];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -169,9 +163,7 @@ class Frame implements FrameInterface {
|
|||||||
throw new \UnderflowException('Not enough bytes received to determine reserved bit');
|
throw new \UnderflowException('Not enough bytes received to determine reserved bit');
|
||||||
}
|
}
|
||||||
|
|
||||||
$fbb = sprintf('%08b', ord(substr($this->data, 0, 1)));
|
return 16 == (ord($this->data[0]) & 16);
|
||||||
|
|
||||||
return (boolean)(int)$fbb[3];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -182,7 +174,7 @@ class Frame implements FrameInterface {
|
|||||||
throw new \UnderflowException("Not enough bytes received ({$this->bytesRecvd}) to determine if mask is set");
|
throw new \UnderflowException("Not enough bytes received ({$this->bytesRecvd}) to determine if mask is set");
|
||||||
}
|
}
|
||||||
|
|
||||||
return (boolean)bindec(substr(sprintf('%08b', ord(substr($this->data, 1, 1))), 0, 1));
|
return 128 === (ord($this->data[1]) & 128);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user