Skip to content

Commit

Permalink
Merge pull request #809 from tgxworld/reduce_allocations
Browse files Browse the repository at this point in the history
Reduce allocations
  • Loading branch information
spastorino committed Mar 1, 2015
2 parents 7788a1b + 55cd3ee commit 1a43de5
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/rack/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def unescape(s, encoding = nil)
module_function :unescape

DEFAULT_SEP = /[&;] */n
COMMON_SEP = { ";" => /[;] */n, ";," => /[;,] */n, "&" => /[&] */n }

class << self
attr_accessor :key_space_limit
Expand All @@ -84,9 +85,9 @@ def parse_query(qs, d = nil, &unescaper)

params = KeySpaceConstrainedParams.new

(qs || '').split(d ? /[#{d}] */n : DEFAULT_SEP).each do |p|
(qs || '').split(d ? (COMMON_SEP[d] || /[#{d}] */n) : DEFAULT_SEP).each do |p|
next if p.empty?
k, v = p.split('=', 2).map!(&unescaper)
k, v = p.split('='.freeze, 2).map!(&unescaper)

if cur = params[k]
if cur.class == Array
Expand All @@ -112,8 +113,8 @@ def parse_nested_query(qs, d = nil)
return {} if qs.empty?
params = KeySpaceConstrainedParams.new

(qs || '').split(d ? /[#{d}] */n : DEFAULT_SEP).each do |p|
k, v = p.split('=', 2).map { |s| unescape(s) }
(qs || '').split(d ? (COMMON_SEP[d] || /[#{d}] */n) : DEFAULT_SEP).each do |p|
k, v = p.split('='.freeze, 2).map! { |s| unescape(s) }

normalize_params(params, k, v)
end
Expand Down Expand Up @@ -275,9 +276,9 @@ def select_best_encoding(available_encodings, accept_encoding)
def set_cookie_header!(header, key, value)
case value
when Hash
domain = "; domain=" + value[:domain] if value[:domain]
path = "; path=" + value[:path] if value[:path]
max_age = "; max-age=" + value[:max_age].to_s if value[:max_age]
domain = "; domain=#{value[:domain]}" if value[:domain]
path = "; path=#{value[:path]}" if value[:path]
max_age = "; max-age=#{value[:max_age]}" if value[:max_age]
# There is an RFC mess in the area of date formatting for Cookies. Not
# only are there contradicting RFCs and examples within RFC text, but
# there are also numerous conflicting names of fields and partially
Expand Down

0 comments on commit 1a43de5

Please sign in to comment.