Permalink
Browse files

use a set, avoid calling #unique

  • Loading branch information...
1 parent ea0c368 commit 89b24fe98f215eecfa29812f6cca4d4b4ad37b37 @riffraff committed May 19, 2011
Showing with 8 additions and 11 deletions.
  1. +7 −5 lib/bullet/detector/unused_eager_association.rb
  2. +1 −6 lib/bullet/registry/base.rb
@@ -23,11 +23,13 @@ def self.create_notification(klazz, associations)
end
def self.call_object_association( object, association )
- eager_loadings.similarly_associated( object, association ).
- collect { |related_object| call_object_associations[related_object] }.
- compact.
- flatten.
- uniq
+ all = Set.new
+ eager_loadings.similarly_associated( object, association ).each do |related_object|
+ coa = call_object_associations[related_object]
+ next if coa.nil?
+ all.merge coa
+ end
+ all.to_a
end
def self.diff_object_association( object, association )
@@ -24,19 +24,14 @@ def select( *args, &block )
end
def add( key, value )
- @registry[key] ||= []
+ @registry[key] ||= Set.new
if value.is_a? Array
@registry[key] += value
else
@registry[key] << value
end
- unique( @registry[key] )
end
- private
- def unique( array )
- array.uniq!
- end
end
end
end

0 comments on commit 89b24fe

Please sign in to comment.