Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 33616c5d44a4
Choose a base ref
...
head repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: bbdffc3ee372
Choose a head ref
  • 2 commits
  • 1 file changed
  • 2 contributors

Commits on Aug 5, 2016

  1. Copy the full SHA
    81a0162 View commit details
  2. Merge pull request #3100 from CodeSteak/faster-websocket-masking

    Websocket masking: replace `% 4` with `& 0b11` for performance.
    Ary Borenszweig authored Aug 5, 2016
    Copy the full SHA
    bbdffc3 View commit details
Showing with 3 additions and 3 deletions.
  1. +3 −3 src/http/web_socket/protocol.cr
6 changes: 3 additions & 3 deletions src/http/web_socket/protocol.cr
Original file line number Diff line number Diff line change
@@ -138,8 +138,8 @@ class HTTP::WebSocket::Protocol
@io.write mask_array.to_slice

data.each_with_index do |byte, index|
mask = mask_array[index % 4]
@io.write_byte(byte ^ mask_array[index % 4])
mask = mask_array[index & 0b11] # x & 0b11 == x % 4
@io.write_byte(byte ^ mask_array[index & 0b11])
end
end

@@ -193,7 +193,7 @@ class HTTP::WebSocket::Protocol
@io.read_fully(buffer[0, count])
if masked?
count.times do |i|
buffer[i] ^= @mask[@mask_offset % 4]
buffer[i] ^= @mask[@mask_offset & 0b11] # x & 0b11 == x % 4
@mask_offset += 1
end
end