Skip to content

Commit

Permalink
Remove ObectSpace dumping and start using inherited, it's faster.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordon Bedwell committed Jan 10, 2016
1 parent 88b970f commit 4f20e3e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 25 deletions.
1 change: 1 addition & 0 deletions lib/jekyll/generator.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module Jekyll
class Generator < Plugin
#
end
end
43 changes: 31 additions & 12 deletions lib/jekyll/plugin.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
module Jekyll
class Plugin
PRIORITIES = { :lowest => -100,
:low => -10,
:normal => 0,
:high => 10,
:highest => 100 }
PRIORITIES = {
:low => -10,
:highest => 100,
:lowest => -100,
:normal => 0,
:high => 10
}

# Fetch all the subclasses of this class and its subclasses' subclasses.
#
# Returns an array of descendant classes.
def self.descendants
descendants = []
ObjectSpace.each_object(singleton_class) do |k|
descendants.unshift k unless k == self

def self.inherited(const)
return catch_inheritance(const) do |const_|
catch_inheritance(const_)
end
end

#

def self.catch_inheritance(const)
const.define_singleton_method :inherited do |const_|
(@children ||= Set.new).add const_
if block_given?
yield const_
end
end
descendants
end

#

def self.descendants
@children ||= Set.new
out = @children.map(&:descendants)
out << self unless superclass == Plugin
Set.new(out).flatten
end

# Get or set the priority of this plugin. When called without an
Expand Down
22 changes: 9 additions & 13 deletions lib/jekyll/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,25 +263,21 @@ def site_payload
end

# Get the implementation class for the given Converter.
#
# klass - The Class of the Converter to fetch.
#
# Returns the Converter instance implementing the given Converter.
# klass - The Class of the Converter to fetch.

def find_converter_instance(klass)
converters.find { |c| c.class == klass } || proc { raise "No converter for #{klass}" }.call
converters.find { |klass_| klass_.instance_of?(klass) } || \
raise("No Converters found for #{klass}")
end

# klass - class or module containing the subclasses.
# Returns array of instances of subclasses of parameter.
# Create array of instances of the subclasses of the class or module
# passed in as argument.
#
# klass - class or module containing the subclasses which should be
# instantiated
#
# Returns array of instances of subclasses of parameter
# passed in as argument.

def instantiate_subclasses(klass)
klass.descendants.select do |c|
!safe || c.safe
end.sort.map do |c|
klass.descendants.select { |c| !safe || c.safe }.sort.map do |c|
c.new(config)
end
end
Expand Down

0 comments on commit 4f20e3e

Please sign in to comment.