1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

base64.rb: improve performance of Base64.urlsafe_encode64

* lib/base64.rb: avoid unnecessary memory allocations
This commit is contained in:
Konstantin Papkovskiy 2017-08-15 17:35:58 +03:00 committed by Yusuke Endoh
parent 3ca3c8d768
commit 1bdabaa6b1

View file

@ -81,8 +81,9 @@ module Base64
# Note that the result can still contain '='.
# You can remove the padding by setting +padding+ as false.
def urlsafe_encode64(bin, padding: true)
str = strict_encode64(bin).tr("+/", "-_")
str = str.delete("=") unless padding
str = strict_encode64(bin)
str.tr!("+/", "-_")
str.delete!("=") unless padding
str
end