1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Improve performance and memory usage for options_for_select with Ruby 1.8.7

This commit is contained in:
Christos Zisopoulos 2011-07-27 16:12:22 +02:00 committed by Xavier Noria
parent 091e767c2d
commit 8faeed1d71

View file

@ -323,12 +323,12 @@ module ActionView
return container if String === container return container if String === container
selected, disabled = extract_selected_and_disabled(selected).map do | r | selected, disabled = extract_selected_and_disabled(selected).map do | r |
Array.wrap(r).map(&:to_s) Array.wrap(r).map { |item| item.to_s }
end end
container.map do |element| container.map do |element|
html_attributes = option_html_attributes(element) html_attributes = option_html_attributes(element)
text, value = option_text_and_value(element).map(&:to_s) text, value = option_text_and_value(element).map { |item| item.to_s }
selected_attribute = ' selected="selected"' if option_value_selected?(value, selected) selected_attribute = ' selected="selected"' if option_value_selected?(value, selected)
disabled_attribute = ' disabled="disabled"' if disabled && option_value_selected?(value, disabled) disabled_attribute = ' disabled="disabled"' if disabled && option_value_selected?(value, disabled)
%(<option value="#{ERB::Util.html_escape(value)}"#{selected_attribute}#{disabled_attribute}#{html_attributes}>#{ERB::Util.html_escape(text)}</option>) %(<option value="#{ERB::Util.html_escape(value)}"#{selected_attribute}#{disabled_attribute}#{html_attributes}>#{ERB::Util.html_escape(text)}</option>)