提交 ffc9ed3d 编写于 作者: E Eugene Kenny

Reduce string allocations in read/write_attribute

When `attr_name` is passed as a symbol, it's currently converted to a
string by `attribute_alias?`, and potentially also `attribute_alias`,
as well as by the `read_attribute`/`write_attribute` method itself.

By converting `attr_name` to a string up front, the extra allocations
related to attribute aliases can be avoided.
上级 26a202a9
......@@ -29,10 +29,9 @@ def #{temp_method_name}
# it has been typecast (for example, "2004-12-12" in a date column is cast
# to a date object, like Date.new(2004, 12, 12)).
def read_attribute(attr_name, &block)
name = if self.class.attribute_alias?(attr_name)
self.class.attribute_alias(attr_name).to_s
else
attr_name.to_s
name = attr_name.to_s
if self.class.attribute_alias?(name)
name = self.class.attribute_alias(name)
end
primary_key = self.class.primary_key
......
......@@ -33,10 +33,9 @@ def #{temp_method_name}(value)
# specified +value+. Empty strings for Integer and Float columns are
# turned into +nil+.
def write_attribute(attr_name, value)
name = if self.class.attribute_alias?(attr_name)
self.class.attribute_alias(attr_name).to_s
else
attr_name.to_s
name = attr_name.to_s
if self.class.attribute_alias?(name)
name = self.class.attribute_alias(name)
end
primary_key = self.class.primary_key
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册