aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/object
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2008-06-07 17:23:25 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2008-06-08 00:35:36 -0700
commit6c970d79a064b953d3d9555a362a1ad1e0058d1c (patch)
treed46dd2b359d48d0a7713774173a1aacb12b9aafd /activesupport/lib/active_support/core_ext/object
parent06b6f435cb7ed4b171eb600d3a9286829b8b2482 (diff)
downloadrails-6c970d79a064b953d3d9555a362a1ad1e0058d1c.tar.gz
rails-6c970d79a064b953d3d9555a362a1ad1e0058d1c.tar.bz2
rails-6c970d79a064b953d3d9555a362a1ad1e0058d1c.zip
Performance: faster Object.subclasses_of
Diffstat (limited to 'activesupport/lib/active_support/core_ext/object')
-rw-r--r--activesupport/lib/active_support/core_ext/object/extending.rb17
1 files changed, 9 insertions, 8 deletions
diff --git a/activesupport/lib/active_support/core_ext/object/extending.rb b/activesupport/lib/active_support/core_ext/object/extending.rb
index 43a2be916e..082e98a297 100644
--- a/activesupport/lib/active_support/core_ext/object/extending.rb
+++ b/activesupport/lib/active_support/core_ext/object/extending.rb
@@ -3,17 +3,18 @@ class Object
Class.remove_class(*subclasses_of(*superclasses))
end
+ # Exclude this class unless it's a subclass of our supers and is defined.
+ # We check defined? in case we find a removed class that has yet to be
+ # garbage collected. This also fails for anonymous classes -- please
+ # submit a patch if you have a workaround.
def subclasses_of(*superclasses) #:nodoc:
subclasses = []
- # Exclude this class unless it's a subclass of our supers and is defined.
- # We check defined? in case we find a removed class that has yet to be
- # garbage collected. This also fails for anonymous classes -- please
- # submit a patch if you have a workaround.
- ObjectSpace.each_object(Class) do |k|
- if superclasses.any? { |superclass| k < superclass } &&
- (k.name.blank? || eval("defined?(::#{k}) && ::#{k}.object_id == k.object_id"))
- subclasses << k
+ superclasses.each do |sup|
+ ObjectSpace.each_object(class << sup; self; end) do |k|
+ if k != sup && (k.name.blank? || eval("defined?(::#{k}) && ::#{k}.object_id == k.object_id"))
+ subclasses << k
+ end
end
end