diff options
author | Jean Boussier <jean.boussier@gmail.com> | 2019-04-05 14:45:05 +0200 |
---|---|---|
committer | Jean Boussier <jean.boussier@gmail.com> | 2019-04-09 13:54:49 +0200 |
commit | 6f26e99cef4b6f20be8ef5cf7fee4b4755baaaec (patch) | |
tree | 823a7fd9cb13247da40b1387cc7dc7f4dd8496fd /activerecord/lib/active_record/connection_adapters/postgresql | |
parent | ac786cd1f2c39ea4c9eefeb23ceaab8fe3b242ec (diff) | |
download | rails-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/postgresql')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/type_metadata.rb | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/type_metadata.rb b/activerecord/lib/active_record/connection_adapters/postgresql/type_metadata.rb index cd69d28139..403b3ead98 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/type_metadata.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/type_metadata.rb @@ -22,19 +22,20 @@ module ActiveRecord def ==(other) other.is_a?(PostgreSQLTypeMetadata) && - attributes_for_hash == other.attributes_for_hash + __getobj__ == other.__getobj__ && + oid == other.oid && + fmod == other.fmod && + array == other.array end alias eql? == def hash - attributes_for_hash.hash + PostgreSQLTypeMetadata.hash ^ + __getobj__.hash ^ + oid.hash ^ + fmod.hash ^ + array.hash end - - protected - - def attributes_for_hash - [self.class, @type_metadata, oid, fmod] - end end end end |