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:
parent
3ca3c8d768
commit
1bdabaa6b1
1 changed files with 3 additions and 2 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue