Skip to content

Commit

Permalink
Fixes Issue #106: deep_merge recursively slow
Browse files Browse the repository at this point in the history
The call to custom_writer within deep_merge was exponentially converting the values (unnecessarily, since they were just converted within deep_merge).  Added an optional param to custom_writer to suppress the conversion.  Unfortunately, had to also add the param to coercion's customer_writer method as well (which is just ignored) to not break the inheritance.

All tests pass.
  • Loading branch information
davemitchell committed Jul 28, 2013
1 parent 3321005 commit 35efddc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/hashie/extensions/coercion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def []=(key, value)
super(key, value)
end

def custom_writer(key, value)
def custom_writer(key, value, convert=true)
self[key] = value
end

Expand Down
8 changes: 4 additions & 4 deletions lib/hashie/mash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ def custom_reader(key)
# Sets an attribute in the Mash. Key will be converted to
# a string before it is set, and Hashes will be converted
# into Mashes for nesting purposes.
def custom_writer(key,value) #:nodoc:
regular_writer(convert_key(key), convert_value(value))
def custom_writer(key,value,convert=true) #:nodoc:
regular_writer(convert_key(key), convert ? convert_value(value) : value)
end

alias_method :[], :custom_reader
Expand Down Expand Up @@ -154,8 +154,8 @@ def deep_update(other_hash, &blk)
custom_reader(key).deep_update(v, &blk)
else
value = convert_value(v, true)
value = blk.call(key, self[k], value) if blk
custom_writer(key, value)
value = convert_value(blk.call(key, self[k], value), true) if blk
custom_writer(key, value, false)
end
end
self
Expand Down

0 comments on commit 35efddc

Please sign in to comment.