Skip to content

Commit

Permalink
Reduce allocation on typecasting step
Browse files Browse the repository at this point in the history
  • Loading branch information
davydovanton committed Mar 25, 2016
1 parent e9cf43a commit 1c11825
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/shallow_attributes/class_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ def attribute(name, type, options = {})
def initialize_setter(name, type, options)
module_eval <<-EOS, __FILE__, __LINE__ + 1
def #{name}=(value)
@#{name} = ShallowAttributes::Type.coerce(#{type}, value, #{options})
@#{name} = if value.is_a?(#{type}) && !value.is_a?(Array)
value
else
ShallowAttributes::Type.coerce(#{type}, value, #{options})
end
@attributes[:#{name}] = @#{name}
end
EOS
Expand Down

0 comments on commit 1c11825

Please sign in to comment.