diff options
author | schneems <richard.schneeman@gmail.com> | 2015-07-26 14:37:21 -0500 |
---|---|---|
committer | schneems <richard.schneeman@gmail.com> | 2015-07-30 12:31:05 -0500 |
commit | 1f831fefe226ed42e89c0b58076f5b6d66588d7e (patch) | |
tree | 4906ec742b7fe1f4283d362a2b1b783f19ff978a /actionview/lib | |
parent | 0d7a714dcae69668429c4b79e36f1b47d6c898e4 (diff) | |
download | rails-1f831fefe226ed42e89c0b58076f5b6d66588d7e.tar.gz rails-1f831fefe226ed42e89c0b58076f5b6d66588d7e.tar.bz2 rails-1f831fefe226ed42e89c0b58076f5b6d66588d7e.zip |
Don't allocate array when not necessary
In the `tag_options` method an array is used to build up elements, then `Array#*` (which is an alias for `Array#join` is called to turn the array into a string. Instead of allocating an array to build a string, we can build the string we want from the beginning.
Saved: 121,743 bytes 893 objects
Diffstat (limited to 'actionview/lib')
-rw-r--r-- | actionview/lib/action_view/helpers/tag_helper.rb | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/actionview/lib/action_view/helpers/tag_helper.rb b/actionview/lib/action_view/helpers/tag_helper.rb index a821bd9543..30af09cbac 100644 --- a/actionview/lib/action_view/helpers/tag_helper.rb +++ b/actionview/lib/action_view/helpers/tag_helper.rb @@ -149,19 +149,20 @@ module ActionView def tag_options(options, escape = true) return if options.blank? - attrs = [] + output = "" + sep = " ".freeze options.each_pair do |key, value| if TAG_PREFIXES.include?(key) && value.is_a?(Hash) value.each_pair do |k, v| - attrs << prefix_tag_option(key, k, v, escape) + output << sep + prefix_tag_option(key, k, v, escape) end elsif BOOLEAN_ATTRIBUTES.include?(key) - attrs << boolean_tag_option(key) if value + output << sep + boolean_tag_option(key) if value elsif !value.nil? - attrs << tag_option(key, value, escape) + output << sep + tag_option(key, value, escape) end end - " ".freeze + attrs * ' '.freeze unless attrs.empty? + output unless output.empty? end def prefix_tag_option(prefix, key, value, escape) |