Reduce repeated array inclusion check

Currently we check if "tag" is present in LANGUAGE_MODULES for every
String dep, even if tag is nil. Stop doing this, and make the
LANGUAGE_MODULES array into a Set instead to improve lookup performance.
This commit is contained in:
Jack Nagel 2013-04-16 03:31:29 -05:00
parent 3a0726406b
commit 0fb4f9c426

View File

@ -2,6 +2,7 @@ require 'dependency'
require 'dependencies' require 'dependencies'
require 'requirement' require 'requirement'
require 'requirements' require 'requirements'
require 'set'
## A dependency is a formula that another formula needs to install. ## A dependency is a formula that another formula needs to install.
## A requirement is something other than a formula that another formula ## A requirement is something other than a formula that another formula
@ -15,7 +16,7 @@ require 'requirements'
# specifications into the proper kinds of dependencies and requirements. # specifications into the proper kinds of dependencies and requirements.
class DependencyCollector class DependencyCollector
# Define the languages that we can handle as external dependencies. # Define the languages that we can handle as external dependencies.
LANGUAGE_MODULES = [ LANGUAGE_MODULES = Set[
:chicken, :jruby, :lua, :node, :ocaml, :perl, :python, :rbx, :ruby :chicken, :jruby, :lua, :node, :ocaml, :perl, :python, :rbx, :ruby
].freeze ].freeze
@ -52,7 +53,7 @@ class DependencyCollector
when Symbol when Symbol
parse_symbol_spec(spec, tag) parse_symbol_spec(spec, tag)
when String when String
if LANGUAGE_MODULES.include? tag if tag && LANGUAGE_MODULES.include?(tag)
LanguageModuleDependency.new(tag, spec) LanguageModuleDependency.new(tag, spec)
else else
Dependency.new(spec, tag) Dependency.new(spec, tag)