From 75cdbc5b10d4813316b38a3588829debadc7fb7d Mon Sep 17 00:00:00 2001 From: Paul Kmiec Date: Mon, 22 May 2023 21:10:08 -0700 Subject: Use #== and #eql? from BasicObject Prior to https://github.com/caxlsx/caxlsx/pull/223, SimpleTypeList was just an object and inheritied #== / #eql? from BasicObject. These versions are fast as they just compare whether two objects sit in the same memory location. After https://github.com/caxlsx/caxlsx/pull/223, we started to inherit #== / #eql? from Array. These are slow as they crawl all the elements in the Array. This commit restores the original version of #== / #eql?. --- lib/axlsx/util/simple_typed_list.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/axlsx/util/simple_typed_list.rb b/lib/axlsx/util/simple_typed_list.rb index c3910fca..e74e25e3 100644 --- a/lib/axlsx/util/simple_typed_list.rb +++ b/lib/axlsx/util/simple_typed_list.rb @@ -15,6 +15,12 @@ module Axlsx undef_method name end + # We often call index(element) on instances of SimpleTypedList. Thus, we do not want to inherit Array + # implementation of == / eql? which walks the elements calling == / eql?. Instead we want the fast + # and original versions from BasicObject. + alias :== :equal? + alias :eql? :equal? + # Creats a new typed list # @param [Array, Class] type An array of Class objects or a single Class object # @param [String] serialize_as The tag name to use in serialization -- cgit v1.2.3