aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2016-01-27 17:46:06 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2016-01-27 18:28:04 -0800
commit542b2e9c9b7e24f5337fd529a36f9d89f727e189 (patch)
tree078738255d52bd98d97df92f069f523c8cadcffd /actionpack
parent2c131141ca5018f41f85be429a02afac93a0241d (diff)
downloadrails-542b2e9c9b7e24f5337fd529a36f9d89f727e189.tar.gz
rails-542b2e9c9b7e24f5337fd529a36f9d89f727e189.tar.bz2
rails-542b2e9c9b7e24f5337fd529a36f9d89f727e189.zip
change `@text_xml_idx` to an lvar and cache it on the stack
this eliminates the ivar lookup and also eliminates the `||=` conditional that happens every time we called the `text_xml_idx` method.
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_dispatch/http/mime_type.rb24
1 files changed, 11 insertions, 13 deletions
diff --git a/actionpack/lib/action_dispatch/http/mime_type.rb b/actionpack/lib/action_dispatch/http/mime_type.rb
index 6abbf9c754..a90c691ff7 100644
--- a/actionpack/lib/action_dispatch/http/mime_type.rb
+++ b/actionpack/lib/action_dispatch/http/mime_type.rb
@@ -116,13 +116,18 @@ module Mime
def assort!
sort!
+ text_xml_idx = index('text/xml')
+
# 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.q, app_xml.q].max # set the q value to the max of the two
- exchange_xml_items if app_xml_idx > text_xml_idx # make sure app_xml is ahead of text_xml in the list
+ app_xml.q = [text_xml(text_xml_idx).q, app_xml.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
+ end
delete_at(text_xml_idx) # delete text_xml from the list
elsif text_xml_idx
- text_xml.name = Mime[:xml].to_s
+ text_xml(text_xml_idx).name = Mime[:xml].to_s
end
# Look for more specific XML-based types and sort them ahead of app/xml
@@ -146,25 +151,18 @@ module Mime
end
private
- def text_xml_idx
- @text_xml_idx ||= index('text/xml')
- end
-
def app_xml_idx
@app_xml_idx ||= index(Mime[:xml].to_s)
end
- def text_xml
- self[text_xml_idx]
- end
+ alias :text_xml :[]
def app_xml
self[app_xml_idx]
end
- def exchange_xml_items
- self[app_xml_idx], self[text_xml_idx] = text_xml, app_xml
- @app_xml_idx, @text_xml_idx = text_xml_idx, app_xml_idx
+ def exchange_xml_items(text_xml_idx)
+ self[app_xml_idx], self[text_xml_idx] = text_xml(text_xml_idx), app_xml
end
end