aboutsummaryrefslogtreecommitdiffstats
path: root/lib/base64.rb
diff options
context:
space:
mode:
authorKonstantin Papkovskiy <konstantin@papkovskiy.com>2017-08-15 17:35:58 +0300
committerYusuke Endoh <mame@ruby-lang.org>2019-12-10 14:32:35 +0900
commit1bdabaa6b13344c195698ca5b0ced323cb93e2e1 (patch)
tree3a82f48f544621e75aee4223e954f090792131e2 /lib/base64.rb
parent3ca3c8d768f6d81da72df4798736c2e0059d19f9 (diff)
downloadruby-1bdabaa6b13344c195698ca5b0ced323cb93e2e1.tar.gz
base64.rb: improve performance of Base64.urlsafe_encode64
* lib/base64.rb: avoid unnecessary memory allocations
Diffstat (limited to 'lib/base64.rb')
-rw-r--r--lib/base64.rb5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/base64.rb b/lib/base64.rb
index 24f0b02966..5c8df841f1 100644
--- a/lib/base64.rb
+++ b/lib/base64.rb
@@ -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