Browse files

Use sets defined once instead of arrays declared in line where order

doesn't matter.

Very minor perf improvement, evidence of which is either anecdotal
(rspec's suite appears to run about 0.1 second faster on average) or
assumed based on benchmarks posted at
https://github.com/rspec/rspec-expectations/blob/master/benchmarks/set_vs_array_include.rb
  • Loading branch information...
1 parent 47d7d0c commit d8af26ebbd10bbe65182ff4aa4e575cdfa779386 @dchelimsky dchelimsky committed Jan 12, 2012
View
2 lib/rspec/core/configuration_options.rb
@@ -38,7 +38,7 @@ def filter_manager
private
- NON_FORCED_OPTIONS = [:debug, :requires, :libs, :files_or_directories_to_run, :line_numbers, :full_description]
+ NON_FORCED_OPTIONS = [:debug, :requires, :libs, :files_or_directories_to_run, :line_numbers, :full_description].to_set
def force?(key)
!NON_FORCED_OPTIONS.include?(key)
View
4 lib/rspec/core/drb_options.rb
@@ -52,9 +52,11 @@ def add_line_numbers(argv)
end
end
+ BOOLEAN_FILTERS = [:if, :unless].to_set
+
def add_filter(argv, name, hash)
hash.each_pair do |k, v|
- next if [:if,:unless].include?(k)
+ next if BOOLEAN_FILTERS.include?(k)
tag = name == :inclusion ? k.to_s : "~#{k}"
tag << ":#{v}" if v.is_a?(String)
argv << "--tag" << tag
View
2 lib/rspec/core/filter_manager.rb
@@ -71,7 +71,7 @@ class FilterManager
:unless => lambda { |value| value }
}
- STANDALONE_FILTERS = [:locations, :line_numbers, :full_description]
+ STANDALONE_FILTERS = [:locations, :line_numbers, :full_description].to_set
module Describable
PROC_HEX_NUMBER = /0x[0-9a-f]+@/
View
4 lib/rspec/core/hooks.rb
@@ -398,8 +398,10 @@ def find_hook(hook, scope, example_group_class, example = nil)
private
+ SCOPES = [:each, :all, :suite].to_set
+
def scope_and_options_from(*args)
- scope = if [:each, :all, :suite].include?(args.first)
+ scope = if SCOPES.include?(args.first)
args.shift
elsif args.any? { |a| a.is_a?(Symbol) }
raise ArgumentError.new("You must explicitly give a scope (:each, :all, or :suite) when using symbols as metadata for a hook.")

0 comments on commit d8af26e

Please sign in to comment.