Skip to content

Commit e7bf9f9

Browse files
committed
Merge pull request rails#23682 from ShikChen/fast_strxor
Improve the performance of string xor operation
2 parents 44888ec + e35e19a commit e7bf9f9

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

actionpack/lib/action_controller/metal/request_forgery_protection.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,8 @@ def per_form_csrf_token(session, action_path, method)
379379

380380
def xor_byte_strings(s1, s2)
381381
s2_bytes = s2.bytes
382-
s1.bytes.map.with_index { |c1, i| c1 ^ s2_bytes[i] }.pack('c*')
382+
s1.each_byte.with_index { |c1, i| s2_bytes[i] ^= c1 }
383+
s2_bytes.pack('C*')
383384
end
384385

385386
# The form's authenticity parameter. Override to provide your own.

0 commit comments

Comments
 (0)