Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Perf: get the right collection the first time

- turns out it is faster to inject over an array than to collection a
  bunch of arrays and flatten them
  • Loading branch information...
commit 8e550ad0aa12d17a1ea8723c8461c578c77ffabd 1 parent 988b345
David Chelimsky dchelimsky authored
Showing with 4 additions and 4 deletions.
  1. +4 −4 lib/rspec/core/example_group.rb
8 lib/rspec/core/example_group.rb
View
@@ -95,7 +95,7 @@ def self.filtered_examples
end
def self.descendant_filtered_examples
- @descendant_filtered_examples ||= filtered_examples + children.collect{|c| c.descendant_filtered_examples}.flatten
+ @descendant_filtered_examples ||= filtered_examples + children.inject([]){|l,c| l + c.descendant_filtered_examples}
end
def self.metadata
@@ -138,7 +138,7 @@ def self.children
end
def self.descendants
- @_descendants ||= [self] + children.collect {|c| c.descendants}.flatten
+ @_descendants ||= [self] + children.inject([]) {|list, c| list + c.descendants}
end
def self.ancestors
@@ -216,7 +216,7 @@ def self.eval_after_alls(example_group_instance)
end
def self.around_hooks
- @around_hooks ||= (world.find_hook(:around, :each, self) + ancestors.reverse.map{|a| a.find_hook(:around, :each, self)}).flatten
+ @around_hooks ||= (world.find_hook(:around, :each, self) + ancestors.reverse.inject([]){|l,a| l + a.find_hook(:around, :each, self)})
end
def self.run(reporter)
@@ -276,7 +276,7 @@ def self.all_apply?(filters)
def self.declaration_line_numbers
@declaration_line_numbers ||= [metadata[:example_group][:line_number]] +
examples.collect {|e| e.metadata[:line_number]} +
- children.collect {|c| c.declaration_line_numbers}.flatten
+ children.inject([]) {|l,c| l + c.declaration_line_numbers}
end
def self.top_level_description
Please sign in to comment.
Something went wrong with that request. Please try again.