diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2018-05-22 13:14:27 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-22 13:14:27 -0400 |
commit | 7ee898ca18797c70ed71605087474032e2289909 (patch) | |
tree | 3aceae8b26d91b3dc63dc42b892e8bc31ba3349e | |
parent | 6c574ac58993512f975ddaf1f679c5956cc576df (diff) | |
parent | 8b10a9414dd30817b1fc9c4c8cb7600cca0d15b3 (diff) | |
download | rails-7ee898ca18797c70ed71605087474032e2289909.tar.gz rails-7ee898ca18797c70ed71605087474032e2289909.tar.bz2 rails-7ee898ca18797c70ed71605087474032e2289909.zip |
Merge pull request #32931 from jeremyevans/fast-xor
Speed up xor_byte_strings by 70%
-rw-r--r-- | actionpack/lib/action_controller/metal/request_forgery_protection.rb | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/actionpack/lib/action_controller/metal/request_forgery_protection.rb b/actionpack/lib/action_controller/metal/request_forgery_protection.rb index fc9cf8aaff..953f3c47ed 100644 --- a/actionpack/lib/action_controller/metal/request_forgery_protection.rb +++ b/actionpack/lib/action_controller/metal/request_forgery_protection.rb @@ -400,9 +400,14 @@ module ActionController #:nodoc: end def xor_byte_strings(s1, s2) # :doc: - s2_bytes = s2.bytes - s1.each_byte.with_index { |c1, i| s2_bytes[i] ^= c1 } - s2_bytes.pack("C*") + s2 = s2.dup + size = s1.bytesize + i = 0 + while i < size + s2.setbyte(i, s1.getbyte(i) ^ s2.getbyte(i)) + i += 1 + end + s2 end # The form's authenticity parameter. Override to provide your own. |