aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/column.rb
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2019-04-05 14:45:05 +0200
committerJean Boussier <jean.boussier@gmail.com>2019-04-09 13:54:49 +0200
commit6f26e99cef4b6f20be8ef5cf7fee4b4755baaaec (patch)
tree823a7fd9cb13247da40b1387cc7dc7f4dd8496fd /activerecord/lib/active_record/connection_adapters/column.rb
parentac786cd1f2c39ea4c9eefeb23ceaab8fe3b242ec (diff)
downloadrails-6f26e99cef4b6f20be8ef5cf7fee4b4755baaaec.tar.gz
rails-6f26e99cef4b6f20be8ef5cf7fee4b4755baaaec.tar.bz2
rails-6f26e99cef4b6f20be8ef5cf7fee4b4755baaaec.zip
Improve == and hash methods on various schema cache structs to be allocation free.
The previous implementation would allocate 2 arrays per comparisons. I tried relying on Struct, but they do allocate one Hash inside `Struct#hash`.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/column.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/column.rb21
1 files changed, 13 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/column.rb b/activerecord/lib/active_record/connection_adapters/column.rb
index 8c294ccf5a..21c5e43ea0 100644
--- a/activerecord/lib/active_record/connection_adapters/column.rb
+++ b/activerecord/lib/active_record/connection_adapters/column.rb
@@ -63,19 +63,24 @@ module ActiveRecord
def ==(other)
other.is_a?(Column) &&
- attributes_for_hash == other.attributes_for_hash
+ name == other.name &&
+ default == other.default &&
+ sql_type_metadata == other.sql_type_metadata &&
+ null == other.null &&
+ default_function == other.default_function &&
+ collation == other.collation
end
alias :eql? :==
def hash
- attributes_for_hash.hash
+ Column.hash ^
+ name.hash ^
+ default.hash ^
+ sql_type_metadata.hash ^
+ null.hash ^
+ default_function.hash ^
+ collation.hash
end
-
- protected
-
- def attributes_for_hash
- [self.class, name, default, sql_type_metadata, null, default_function, collation, comment]
- end
end
class NullColumn < Column