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 коммит произвёл Yusuke Endoh
Родитель 3ca3c8d768
Коммит 1bdabaa6b1
1 изменённых файлов: 3 добавлений и 2 удалений

Просмотреть файл

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