1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #31821 from composerinteralia/extra-to_s

Avoid extra calls to to_s
This commit is contained in:
George Claghorn 2018-01-29 15:56:53 -05:00 committed by GitHub
commit ca1d13a158
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 9 additions and 9 deletions

View file

@ -53,7 +53,7 @@ module ActiveRecord
# Implements the ids writer method, e.g. foo.item_ids= for Foo.has_many :items # Implements the ids writer method, e.g. foo.item_ids= for Foo.has_many :items
def ids_writer(ids) def ids_writer(ids)
primary_key = reflection.association_primary_key primary_key = reflection.association_primary_key
pk_type = klass.type_for_attribute(primary_key.to_s) pk_type = klass.type_for_attribute(primary_key)
ids = Array(ids).reject(&:blank?) ids = Array(ids).reject(&:blank?)
ids.map! { |i| pk_type.cast(i) } ids.map! { |i| pk_type.cast(i) }

View file

@ -82,11 +82,11 @@ module ActiveRecord
end end
def association_key_type def association_key_type
@klass.type_for_attribute(association_key_name.to_s).type @klass.type_for_attribute(association_key_name).type
end end
def owner_key_type def owner_key_type
@model.type_for_attribute(owner_key_name.to_s).type @model.type_for_attribute(owner_key_name).type
end end
def load_records(&block) def load_records(&block)

View file

@ -15,7 +15,7 @@ module ActiveRecord
if collection.eager_loading? if collection.eager_loading?
collection = collection.send(:apply_join_dependency) collection = collection.send(:apply_join_dependency)
end end
column_type = type_for_attribute(timestamp_column.to_s) column_type = type_for_attribute(timestamp_column)
column = connection.column_name_from_arel_node(collection.arel_attribute(timestamp_column)) column = connection.column_name_from_arel_node(collection.arel_attribute(timestamp_column))
select_values = "COUNT(*) AS #{connection.quote_column_name("size")}, MAX(%s) AS timestamp" select_values = "COUNT(*) AS #{connection.quote_column_name("size")}, MAX(%s) AS timestamp"

View file

@ -242,7 +242,7 @@ module ActiveRecord
def aggregate_column(column_name) def aggregate_column(column_name)
return column_name if Arel::Expressions === column_name return column_name if Arel::Expressions === column_name
if @klass.has_attribute?(column_name.to_s) || @klass.attribute_alias?(column_name.to_s) if @klass.has_attribute?(column_name) || @klass.attribute_alias?(column_name)
@klass.arel_attribute(column_name) @klass.arel_attribute(column_name)
else else
Arel.sql(column_name == :all ? "*" : column_name.to_s) Arel.sql(column_name == :all ? "*" : column_name.to_s)

View file

@ -84,7 +84,7 @@ module ActiveRecord
def sanitize_sql_hash_for_assignment(attrs, table) def sanitize_sql_hash_for_assignment(attrs, table)
c = connection c = connection
attrs.map do |attr, value| attrs.map do |attr, value|
type = type_for_attribute(attr.to_s) type = type_for_attribute(attr)
value = type.serialize(type.cast(value)) value = type.serialize(type.cast(value))
"#{c.quote_table_name_for_assignment(table, attr)} = #{c.quote(value)}" "#{c.quote_table_name_for_assignment(table, attr)} = #{c.quote(value)}"
end.join(", ") end.join(", ")

View file

@ -135,7 +135,7 @@ module ActiveRecord
end end
def store_accessor_for(store_attribute) def store_accessor_for(store_attribute)
type_for_attribute(store_attribute.to_s).accessor type_for_attribute(store_attribute).accessor
end end
class HashAccessor # :nodoc: class HashAccessor # :nodoc:

View file

@ -30,7 +30,7 @@ module ActiveRecord
def type(column_name) def type(column_name)
if klass if klass
klass.type_for_attribute(column_name.to_s) klass.type_for_attribute(column_name)
else else
Type.default_value Type.default_value
end end

View file

@ -9,7 +9,7 @@ module ActiveRecord
def type_cast_for_database(attr_name, value) def type_cast_for_database(attr_name, value)
return value if value.is_a?(Arel::Nodes::BindParam) return value if value.is_a?(Arel::Nodes::BindParam)
type = types.type_for_attribute(attr_name.to_s) type = types.type_for_attribute(attr_name)
type.serialize(value) type.serialize(value)
end end