From ce50c6ceb414c28ac949176b41dbaa6cea748b09 Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Sat, 30 May 2015 23:28:31 -0400 Subject: [PATCH] Frame masking perf refs ratchetphp/ratchet#226 --- src/Messaging/Protocol/Frame.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Messaging/Protocol/Frame.php b/src/Messaging/Protocol/Frame.php index 4018d7a..a06d22e 100644 --- a/src/Messaging/Protocol/Frame.php +++ b/src/Messaging/Protocol/Frame.php @@ -303,6 +303,16 @@ class Frame implements FrameInterface { $payload = substr($this->data, $this->getPayloadStartingByte(), $this->getPayloadLength()); } + $len = strlen($payload); + + if (0 === $len) { + return ''; + } + + return $payload ^ str_pad('', $len, $maskingKey, STR_PAD_RIGHT); + + // TODO: Remove this before publish - keeping methods here to compare performance (above is faster but need control against v0.3.3) + $applied = ''; for ($i = 0, $len = strlen($payload); $i < $len; $i++) { $applied .= $payload[$i] ^ $maskingKey[$i % static::MASK_LENGTH];