[rubygems/rubygems] Make Bundler::Dependency
more memory efficient
When resolving from scratch a Gemfile including only `"gem "rails", "~> 8.0.1"`, I get the following results: ### Before Total allocated: 288.21 MB (3498515 objects) Total retained: 119.10 MB (1357976 objects) ### After Total allocated: 277.44 MB (3383182 objects) Total retained: 117.55 MB (1338622 objects) https://github.com/rubygems/rubygems/commit/2d3d6e5015
This commit is contained in:
parent
8e7883011a
commit
4c0cf2deed
@ -5,28 +5,89 @@ require_relative "shared_helpers"
|
|||||||
|
|
||||||
module Bundler
|
module Bundler
|
||||||
class Dependency < Gem::Dependency
|
class Dependency < Gem::Dependency
|
||||||
attr_reader :autorequire
|
|
||||||
attr_reader :groups, :platforms, :gemfile, :path, :git, :github, :branch, :ref, :glob
|
|
||||||
|
|
||||||
def initialize(name, version, options = {}, &blk)
|
def initialize(name, version, options = {}, &blk)
|
||||||
type = options["type"] || :runtime
|
type = options["type"] || :runtime
|
||||||
super(name, version, type)
|
super(name, version, type)
|
||||||
|
|
||||||
@groups = Array(options["group"] || :default).map(&:to_sym)
|
@options = options
|
||||||
@source = options["source"]
|
end
|
||||||
@path = options["path"]
|
|
||||||
@git = options["git"]
|
|
||||||
@github = options["github"]
|
|
||||||
@branch = options["branch"]
|
|
||||||
@ref = options["ref"]
|
|
||||||
@glob = options["glob"]
|
|
||||||
@platforms = Array(options["platforms"])
|
|
||||||
@env = options["env"]
|
|
||||||
@should_include = options.fetch("should_include", true)
|
|
||||||
@gemfile = options["gemfile"]
|
|
||||||
@force_ruby_platform = options["force_ruby_platform"] if options.key?("force_ruby_platform")
|
|
||||||
|
|
||||||
@autorequire = Array(options["require"] || []) if options.key?("require")
|
def groups
|
||||||
|
@groups ||= Array(@options["group"] || :default).map(&:to_sym)
|
||||||
|
end
|
||||||
|
|
||||||
|
def source
|
||||||
|
return @source if defined?(@source)
|
||||||
|
|
||||||
|
@source = @options["source"]
|
||||||
|
end
|
||||||
|
|
||||||
|
def path
|
||||||
|
return @path if defined?(@path)
|
||||||
|
|
||||||
|
@path = @options["path"]
|
||||||
|
end
|
||||||
|
|
||||||
|
def git
|
||||||
|
return @git if defined?(@git)
|
||||||
|
|
||||||
|
@git = @options["git"]
|
||||||
|
end
|
||||||
|
|
||||||
|
def github
|
||||||
|
return @github if defined?(@github)
|
||||||
|
|
||||||
|
@github = @options["github"]
|
||||||
|
end
|
||||||
|
|
||||||
|
def branch
|
||||||
|
return @branch if defined?(@branch)
|
||||||
|
|
||||||
|
@branch = @options["branch"]
|
||||||
|
end
|
||||||
|
|
||||||
|
def ref
|
||||||
|
return @ref if defined?(@ref)
|
||||||
|
|
||||||
|
@ref = @options["ref"]
|
||||||
|
end
|
||||||
|
|
||||||
|
def glob
|
||||||
|
return @glob if defined?(@glob)
|
||||||
|
|
||||||
|
@glob = @options["glob"]
|
||||||
|
end
|
||||||
|
|
||||||
|
def platforms
|
||||||
|
@platforms ||= Array(@options["platforms"])
|
||||||
|
end
|
||||||
|
|
||||||
|
def env
|
||||||
|
return @env if defined?(@env)
|
||||||
|
|
||||||
|
@env = @options["env"]
|
||||||
|
end
|
||||||
|
|
||||||
|
def should_include
|
||||||
|
@should_include ||= @options.fetch("should_include", true)
|
||||||
|
end
|
||||||
|
|
||||||
|
def gemfile
|
||||||
|
return @gemfile if defined?(@gemfile)
|
||||||
|
|
||||||
|
@gemfile = @options["gemfile"]
|
||||||
|
end
|
||||||
|
|
||||||
|
def force_ruby_platform
|
||||||
|
return @force_ruby_platform if defined?(@force_ruby_platform)
|
||||||
|
|
||||||
|
@force_ruby_platform = @options["force_ruby_platform"]
|
||||||
|
end
|
||||||
|
|
||||||
|
def autorequire
|
||||||
|
return @autorequire if defined?(@autorequire)
|
||||||
|
|
||||||
|
@autorequire = Array(@options["require"] || []) if @options.key?("require")
|
||||||
end
|
end
|
||||||
|
|
||||||
RUBY_PLATFORM_ARRAY = [Gem::Platform::RUBY].freeze
|
RUBY_PLATFORM_ARRAY = [Gem::Platform::RUBY].freeze
|
||||||
@ -36,17 +97,17 @@ module Bundler
|
|||||||
# passed in the `valid_platforms` parameter
|
# passed in the `valid_platforms` parameter
|
||||||
def gem_platforms(valid_platforms)
|
def gem_platforms(valid_platforms)
|
||||||
return RUBY_PLATFORM_ARRAY if force_ruby_platform
|
return RUBY_PLATFORM_ARRAY if force_ruby_platform
|
||||||
return valid_platforms if @platforms.empty?
|
return valid_platforms if platforms.empty?
|
||||||
|
|
||||||
valid_platforms.select {|p| expanded_platforms.include?(GemHelpers.generic(p)) }
|
valid_platforms.select {|p| expanded_platforms.include?(GemHelpers.generic(p)) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def expanded_platforms
|
def expanded_platforms
|
||||||
@expanded_platforms ||= @platforms.filter_map {|pl| CurrentRuby::PLATFORM_MAP[pl] }.flatten.uniq
|
@expanded_platforms ||= platforms.filter_map {|pl| CurrentRuby::PLATFORM_MAP[pl] }.flatten.uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
def should_include?
|
def should_include?
|
||||||
@should_include && current_env? && current_platform?
|
should_include && current_env? && current_platform?
|
||||||
end
|
end
|
||||||
|
|
||||||
def gemspec_dev_dep?
|
def gemspec_dev_dep?
|
||||||
@ -54,19 +115,19 @@ module Bundler
|
|||||||
end
|
end
|
||||||
|
|
||||||
def current_env?
|
def current_env?
|
||||||
return true unless @env
|
return true unless env
|
||||||
if @env.is_a?(Hash)
|
if env.is_a?(Hash)
|
||||||
@env.all? do |key, val|
|
env.all? do |key, val|
|
||||||
ENV[key.to_s] && (val.is_a?(String) ? ENV[key.to_s] == val : ENV[key.to_s] =~ val)
|
ENV[key.to_s] && (val.is_a?(String) ? ENV[key.to_s] == val : ENV[key.to_s] =~ val)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
ENV[@env.to_s]
|
ENV[env.to_s]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def current_platform?
|
def current_platform?
|
||||||
return true if @platforms.empty?
|
return true if platforms.empty?
|
||||||
@platforms.any? do |p|
|
platforms.any? do |p|
|
||||||
Bundler.current_ruby.send("#{p}?")
|
Bundler.current_ruby.send("#{p}?")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user