This happens in Ruby on Rails's View, where there is a hash for another partial. This hash has about 20 key/value pairs.
There is (in HAML)
- if (some_conditon)
= render :partial => 'some_name', :locals => a_hash.merge({ :extra => true })
- else
-# a lot more processing, including concatenating the partials and return as json
- some_var.each do |item|
- result_html << (render :partial => 'some_name', :locals => a_hash )
-# etc
- response.content_type = "application/json"
= result_html.to_json
So the question is, should the merge
be written as merge!
instead? Because it is no longer needed later, if a new hash is created, a lot of time will be spent for creating this new hash (20 items in hash). If an in-place modification is done, it can use the existing hash structure and add one item to it, which will be a lot faster?