зеркало из https://github.com/github/ruby.git
[ruby/base64] Avoid unnecessary string duplication
String#ljust returns a new string, so whenever we need to add padding, we can replace "-/" in place with String#tr! and avoid creating yet another copy of the string. https://github.com/ruby/base64/commit/6401ef5824
This commit is contained in:
Родитель
1b004ba0db
Коммит
f8000e2931
|
@ -99,9 +99,11 @@ module Base64
|
|||
# NOTE: RFC 4648 does say nothing about unpadded input, but says that
|
||||
# "the excess pad characters MAY also be ignored", so it is inferred that
|
||||
# unpadded input is also acceptable.
|
||||
str = str.tr("-_", "+/")
|
||||
if !str.end_with?("=") && str.length % 4 != 0
|
||||
str = str.ljust((str.length + 3) & ~3, "=")
|
||||
str.tr!("-_", "+/")
|
||||
else
|
||||
str = str.tr("-_", "+/")
|
||||
end
|
||||
strict_decode64(str)
|
||||
end
|
||||
|
|
Загрузка…
Ссылка в новой задаче