Skip to content

Commit

Permalink
minor optimization
Browse files Browse the repository at this point in the history
* Array(list) covers all necessary cases

    $ irb
    2.0.0p0 :001 > Array(nil)
     => []
    2.0.0p0 :002 > Array(:foo)
     => [:foo]
    2.0.0p0 :003 > Array([:foo,:bar])
     => [:foo, :bar]

* Array(list) is considerably faster than list.flatten.compact

    $ time ruby -e "100000.times { [nil].flatten.compact; [:foo].flatten.compact; [[:foo, :bar]].flatten.compact }"
    real 0m0.465s
    user 0m0.461s
    sys  0m0.003s
    $ time ruby -e "100000.times { Array(nil); Array(:foo); Array([:foo, :bar]) }"
    real 0m0.117s
    user 0m0.113s
    sys  0m0.003s
  • Loading branch information
dchelimsky committed Aug 10, 2013
1 parent 625ac90 commit 9f2cb32
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rspec/core/configuration.rb
Expand Up @@ -72,7 +72,7 @@ def self.add_setting(name, opts={})
define_reader name
define_predicate_for name
end
[opts[:alias_with]].flatten.compact.each do |alias_name|
Array(opts[:alias_with]).each do |alias_name|
define_aliases(name, alias_name)
end
end
Expand Down

0 comments on commit 9f2cb32

Please sign in to comment.