uri/common: reduce allocations and retained objects
Thanks to Sam Saffron for this patch, it shows a nice reduction which affects many web applications: require 'memory_profiler' MemoryProfiler.report do require 'uri' end.pretty_print Before: Total allocated: 986643 bytes (15159 objects) Total retained: 246370 bytes (2532 objects) After: Total allocated: 926903 bytes (13665 objects) Total retained: 208570 bytes (1587 objects) * lib/uri/common.rb: reduce allocations and retained objects [ruby-core:85161] [Feature #14410] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62081 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
2e12695929
commit
26b3dc4922
@ -1,4 +1,4 @@
|
|||||||
# frozen_string_literal: false
|
# frozen_string_literal: true
|
||||||
#--
|
#--
|
||||||
# = uri/common.rb
|
# = uri/common.rb
|
||||||
#
|
#
|
||||||
@ -342,17 +342,17 @@ module URI
|
|||||||
|
|
||||||
TBLENCWWWCOMP_ = {} # :nodoc:
|
TBLENCWWWCOMP_ = {} # :nodoc:
|
||||||
256.times do |i|
|
256.times do |i|
|
||||||
TBLENCWWWCOMP_[i.chr] = '%%%02X' % i
|
TBLENCWWWCOMP_[-i.chr] = -('%%%02X' % i)
|
||||||
end
|
end
|
||||||
TBLENCWWWCOMP_[' '] = '+'
|
TBLENCWWWCOMP_[' '] = '+'
|
||||||
TBLENCWWWCOMP_.freeze
|
TBLENCWWWCOMP_.freeze
|
||||||
TBLDECWWWCOMP_ = {} # :nodoc:
|
TBLDECWWWCOMP_ = {} # :nodoc:
|
||||||
256.times do |i|
|
256.times do |i|
|
||||||
h, l = i>>4, i&15
|
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
|
end
|
||||||
TBLDECWWWCOMP_['+'] = ' '
|
TBLDECWWWCOMP_['+'] = ' '
|
||||||
TBLDECWWWCOMP_.freeze
|
TBLDECWWWCOMP_.freeze
|
||||||
@ -468,7 +468,7 @@ module URI
|
|||||||
if isindex
|
if isindex
|
||||||
if sep.empty?
|
if sep.empty?
|
||||||
val = key
|
val = key
|
||||||
key = ''
|
key = +''
|
||||||
end
|
end
|
||||||
isindex = false
|
isindex = false
|
||||||
end
|
end
|
||||||
@ -482,7 +482,7 @@ module URI
|
|||||||
if val
|
if val
|
||||||
val.gsub!(/\+|%\h\h/, TBLDECWWWCOMP_)
|
val.gsub!(/\+|%\h\h/, TBLDECWWWCOMP_)
|
||||||
else
|
else
|
||||||
val = ''
|
val = +''
|
||||||
end
|
end
|
||||||
|
|
||||||
ary << [key, val]
|
ary << [key, val]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user