aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2016-01-27 17:50:16 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2016-01-27 18:28:05 -0800
commitf7f59c2eb732e9cb26060058e0ccac7dc74f324c (patch)
treef0cb778665f72cc262e29423f0dedacc53314d6b /actionpack
parent542b2e9c9b7e24f5337fd529a36f9d89f727e189 (diff)
downloadrails-f7f59c2eb732e9cb26060058e0ccac7dc74f324c.tar.gz
rails-f7f59c2eb732e9cb26060058e0ccac7dc74f324c.tar.bz2
rails-f7f59c2eb732e9cb26060058e0ccac7dc74f324c.zip
change `@app_xml_idx` to an lvar and cache it on the stack
same strategy as `@text_xml_idx`: cache it on the stack to avoid ivar lookups and the `||=` call.
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_dispatch/http/mime_type.rb26
1 files changed, 10 insertions, 16 deletions
diff --git a/actionpack/lib/action_dispatch/http/mime_type.rb b/actionpack/lib/action_dispatch/http/mime_type.rb
index a90c691ff7..d953030139 100644
--- a/actionpack/lib/action_dispatch/http/mime_type.rb
+++ b/actionpack/lib/action_dispatch/http/mime_type.rb
@@ -117,13 +117,14 @@ module Mime
sort!
text_xml_idx = index('text/xml')
+ app_xml_idx = index(Mime[:xml].to_s)
# Take care of the broken text/xml entry by renaming or deleting it
if text_xml_idx && app_xml_idx
- app_xml.q = [text_xml(text_xml_idx).q, app_xml.q].max # set the q value to the max of the two
+ app_xml(app_xml_idx).q = [text_xml(text_xml_idx).q, app_xml(app_xml_idx).q].max # set the q value to the max of the two
if app_xml_idx > text_xml_idx # make sure app_xml is ahead of text_xml in the list
- exchange_xml_items(text_xml_idx)
- @app_xml_idx, text_xml_idx = text_xml_idx, app_xml_idx
+ exchange_xml_items(text_xml_idx, app_xml_idx)
+ app_xml_idx, text_xml_idx = text_xml_idx, app_xml_idx
end
delete_at(text_xml_idx) # delete text_xml from the list
elsif text_xml_idx
@@ -136,11 +137,11 @@ module Mime
while idx < length
type = self[idx]
- break if type.q < app_xml.q
+ break if type.q < app_xml(app_xml_idx).q
if type.name.ends_with? '+xml'
- self[app_xml_idx], self[idx] = self[idx], app_xml
- @app_xml_idx = idx
+ self[app_xml_idx], self[idx] = self[idx], app_xml(app_xml_idx)
+ app_xml_idx = idx
end
idx += 1
end
@@ -151,18 +152,11 @@ module Mime
end
private
- def app_xml_idx
- @app_xml_idx ||= index(Mime[:xml].to_s)
- end
-
alias :text_xml :[]
+ alias :app_xml :[]
- def app_xml
- self[app_xml_idx]
- end
-
- def exchange_xml_items(text_xml_idx)
- self[app_xml_idx], self[text_xml_idx] = text_xml(text_xml_idx), app_xml
+ def exchange_xml_items(text_xml_idx, app_xml_idx)
+ self[app_xml_idx], self[text_xml_idx] = text_xml(text_xml_idx), app_xml(app_xml_idx)
end
end