Skip to content

Commit 00d889b

Browse files
authored
Merge pull request #6 from jcmfernandes/avoid-obj-allocation
Avoid unnecessary string duplication in .urlsafe_decode64
2 parents 1f08f53 + 6401ef5 commit 00d889b

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
/pkg/
77
/spec/reports/
88
/tmp/
9+
Gemfile.lock

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
source "https://rubygems.org"
22

33
gem "rake"
4-
gem "minitest"
4+
gem "test-unit"

lib/base64.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,11 @@ def urlsafe_decode64(str)
9999
# NOTE: RFC 4648 does say nothing about unpadded input, but says that
100100
# "the excess pad characters MAY also be ignored", so it is inferred that
101101
# unpadded input is also acceptable.
102-
str = str.tr("-_", "+/")
103102
if !str.end_with?("=") && str.length % 4 != 0
104103
str = str.ljust((str.length + 3) & ~3, "=")
104+
str.tr!("-_", "+/")
105+
else
106+
str = str.tr("-_", "+/")
105107
end
106108
strict_decode64(str)
107109
end

0 commit comments

Comments
 (0)