Skip to content

Commit ec868ec

Browse files
soylenthsbt
authored andcommitted
base64.rb: improve performance of Base64.urlsafe_encode64
* lib/base64.rb: avoid unnecessary memory allocations
1 parent 5111d7f commit ec868ec

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/base64.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ def strict_decode64(str)
8181
# Note that the result can still contain '='.
8282
# You can remove the padding by setting +padding+ as false.
8383
def urlsafe_encode64(bin, padding: true)
84-
str = strict_encode64(bin).tr("+/", "-_")
85-
str = str.delete("=") unless padding
84+
str = strict_encode64(bin)
85+
str.tr!("+/", "-_")
86+
str.delete!("=") unless padding
8687
str
8788
end
8889

0 commit comments

Comments
 (0)