Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce allocations and retained memory in uri/common.rb #1801

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/uri/common.rb
@@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
#--
# = uri/common.rb
#
Expand Down Expand Up @@ -342,17 +342,17 @@ def self.regexp(schemes = nil)

TBLENCWWWCOMP_ = {} # :nodoc:
256.times do |i|
TBLENCWWWCOMP_[i.chr] = '%%%02X' % i
TBLENCWWWCOMP_[-i.chr] = -('%%%02X' % i)
end
TBLENCWWWCOMP_[' '] = '+'
TBLENCWWWCOMP_.freeze
TBLDECWWWCOMP_ = {} # :nodoc:
256.times do |i|
h, l = i>>4, i&15
TBLDECWWWCOMP_['%%%X%X' % [h, l]] = i.chr
TBLDECWWWCOMP_['%%%x%X' % [h, l]] = i.chr
TBLDECWWWCOMP_['%%%X%x' % [h, l]] = i.chr
TBLDECWWWCOMP_['%%%x%x' % [h, l]] = i.chr
TBLDECWWWCOMP_[-('%%%X%X' % [h, l])] = -i.chr
TBLDECWWWCOMP_[-('%%%x%X' % [h, l])] = -i.chr
TBLDECWWWCOMP_[-('%%%X%x' % [h, l])] = -i.chr
TBLDECWWWCOMP_[-('%%%x%x' % [h, l])] = -i.chr
end
TBLDECWWWCOMP_['+'] = ' '
TBLDECWWWCOMP_.freeze
Expand Down Expand Up @@ -468,7 +468,7 @@ def self.decode_www_form(str, enc=Encoding::UTF_8, separator: '&', use__charset_
if isindex
if sep.empty?
val = key
key = ''
key = +''
end
isindex = false
end
Expand All @@ -482,7 +482,7 @@ def self.decode_www_form(str, enc=Encoding::UTF_8, separator: '&', use__charset_
if val
val.gsub!(/\+|%\h\h/, TBLDECWWWCOMP_)
else
val = ''
val = +''
end

ary << [key, val]
Expand Down