[rubygems/rubygems] Enable Performance/MapCompact
cop
https://github.com/rubygems/rubygems/commit/0c3a65871a
This commit is contained in:
parent
4addaaf4df
commit
963f98a94f
@ -32,11 +32,11 @@ module Bundler
|
||||
|
||||
def dylibs_ldd(path)
|
||||
output = `/usr/bin/ldd #{path.shellescape}`.chomp
|
||||
output.split("\n").map do |l|
|
||||
output.split("\n").filter_map do |l|
|
||||
match = l.match(LDD_REGEX)
|
||||
next if match.nil?
|
||||
match.captures[0]
|
||||
end.compact
|
||||
end
|
||||
end
|
||||
|
||||
def dylibs(path)
|
||||
|
@ -73,11 +73,11 @@ module Bundler
|
||||
end
|
||||
|
||||
def gem_dependencies
|
||||
@gem_dependencies ||= Bundler.definition.specs.map do |spec|
|
||||
@gem_dependencies ||= Bundler.definition.specs.filter_map do |spec|
|
||||
dependency = spec.dependencies.find {|dep| dep.name == gem_name }
|
||||
next unless dependency
|
||||
"#{spec.name} (#{spec.version}) depends on #{gem_name} (#{dependency.requirements_list.join(", ")})"
|
||||
end.compact.sort
|
||||
end.sort
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -341,7 +341,7 @@ module Bundler
|
||||
end
|
||||
|
||||
def spec_git_paths
|
||||
sources.git_sources.map {|s| File.realpath(s.path) if File.exist?(s.path) }.compact
|
||||
sources.git_sources.filter_map {|s| File.realpath(s.path) if File.exist?(s.path) }
|
||||
end
|
||||
|
||||
def groups
|
||||
|
@ -62,7 +62,7 @@ module Bundler
|
||||
end
|
||||
|
||||
def expanded_platforms
|
||||
@expanded_platforms ||= @platforms.map {|pl| PLATFORM_MAP[pl] }.compact.flatten.uniq
|
||||
@expanded_platforms ||= @platforms.filter_map {|pl| PLATFORM_MAP[pl] }.flatten.uniq
|
||||
end
|
||||
|
||||
def should_include?
|
||||
|
@ -66,7 +66,7 @@ module Bundler
|
||||
development_group = opts[:development_group] || :development
|
||||
expanded_path = gemfile_root.join(path)
|
||||
|
||||
gemspecs = Gem::Util.glob_files_in_dir("{,*}.gemspec", expanded_path).map {|g| Bundler.load_gemspec(g) }.compact
|
||||
gemspecs = Gem::Util.glob_files_in_dir("{,*}.gemspec", expanded_path).filter_map {|g| Bundler.load_gemspec(g) }
|
||||
gemspecs.reject! {|s| s.name != name } if name
|
||||
specs_by_name_and_version = gemspecs.group_by {|s| [s.name, s.version] }
|
||||
|
||||
|
@ -63,7 +63,7 @@ module Bundler
|
||||
module_function :select_best_platform_match
|
||||
|
||||
def select_best_local_platform_match(specs, force_ruby: false, most_specific_locked_platform: nil)
|
||||
select_best_platform_match(specs, local_platform, force_ruby: force_ruby).map {|spec| spec.materialize_for_installation(most_specific_locked_platform) }.compact
|
||||
select_best_platform_match(specs, local_platform, force_ruby: force_ruby).filter_map {|spec| spec.materialize_for_installation(most_specific_locked_platform) }
|
||||
end
|
||||
module_function :select_best_local_platform_match
|
||||
|
||||
|
@ -417,7 +417,7 @@ module Bundler
|
||||
end
|
||||
|
||||
def prepare_dependencies(requirements, packages)
|
||||
to_dependency_hash(requirements, packages).map do |dep_package, dep_constraint|
|
||||
to_dependency_hash(requirements, packages).filter_map do |dep_package, dep_constraint|
|
||||
name = dep_package.name
|
||||
|
||||
next [dep_package, dep_constraint] if name == "bundler"
|
||||
@ -443,7 +443,7 @@ module Bundler
|
||||
next unless dep_package.current_platform?
|
||||
|
||||
raise_not_found!(dep_package)
|
||||
end.compact.to_h
|
||||
end.to_h
|
||||
end
|
||||
|
||||
def select_sorted_versions(package, range)
|
||||
|
@ -16,7 +16,7 @@ module Bundler
|
||||
hash[name] = Package.new(name, platforms, **options)
|
||||
end
|
||||
|
||||
@requirements = dependencies.map do |dep|
|
||||
@requirements = dependencies.filter_map do |dep|
|
||||
dep_platforms = dep.gem_platforms(platforms)
|
||||
|
||||
# Dependencies scoped to external platforms are ignored
|
||||
@ -27,7 +27,7 @@ module Bundler
|
||||
@packages[name] = Package.new(name, dep_platforms, **options.merge(dependency: dep))
|
||||
|
||||
dep
|
||||
end.compact
|
||||
end
|
||||
end
|
||||
|
||||
def specs_compatible_with(result)
|
||||
|
@ -263,10 +263,10 @@ module Bundler
|
||||
|
||||
def setup_manpath
|
||||
# Add man/ subdirectories from activated bundles to MANPATH for man(1)
|
||||
manuals = $LOAD_PATH.map do |path|
|
||||
manuals = $LOAD_PATH.filter_map do |path|
|
||||
man_subdir = path.sub(/lib$/, "man")
|
||||
man_subdir unless Dir[man_subdir + "/man?/"].empty?
|
||||
end.compact
|
||||
end
|
||||
|
||||
return if manuals.empty?
|
||||
Bundler::SharedHelpers.set_env "MANPATH", manuals.concat(
|
||||
|
@ -214,7 +214,7 @@ module Bundler
|
||||
|
||||
# Some gem authors put absolute paths in their gemspec
|
||||
# and we have to save them from themselves
|
||||
spec.files = spec.files.map do |path|
|
||||
spec.files = spec.files.filter_map do |path|
|
||||
next path unless /\A#{Pathname::SEPARATOR_PAT}/o.match?(path)
|
||||
next if File.directory?(path)
|
||||
begin
|
||||
@ -222,7 +222,7 @@ module Bundler
|
||||
rescue ArgumentError
|
||||
path
|
||||
end
|
||||
end.compact
|
||||
end
|
||||
|
||||
installer = Path::Installer.new(
|
||||
spec,
|
||||
|
@ -102,7 +102,7 @@ prefix or only the files that are requireable.
|
||||
end
|
||||
|
||||
def files_in_default_gem(spec)
|
||||
spec.files.map do |file|
|
||||
spec.files.filter_map do |file|
|
||||
if file.start_with?("#{spec.bindir}/")
|
||||
[RbConfig::CONFIG["bindir"], file.delete_prefix("#{spec.bindir}/")]
|
||||
else
|
||||
@ -119,7 +119,7 @@ prefix or only the files that are requireable.
|
||||
|
||||
[resolve.delete_suffix(requirable_part), requirable_part]
|
||||
end
|
||||
end.compact
|
||||
end
|
||||
end
|
||||
|
||||
def gem_contents(name)
|
||||
|
@ -252,8 +252,7 @@ EOF
|
||||
|
||||
def rustc_dynamic_linker_flags(dest_dir, crate_name)
|
||||
split_flags("DLDFLAGS").
|
||||
map {|arg| maybe_resolve_ldflag_variable(arg, dest_dir, crate_name) }.
|
||||
compact.
|
||||
filter_map {|arg| maybe_resolve_ldflag_variable(arg, dest_dir, crate_name) }.
|
||||
flat_map {|arg| ldflag_to_link_modifier(arg) }
|
||||
end
|
||||
|
||||
|
@ -183,7 +183,7 @@ class Gem::Resolver
|
||||
# Proceed with resolution! Returns an array of ActivationRequest objects.
|
||||
|
||||
def resolve
|
||||
Gem::Molinillo::Resolver.new(self, self).resolve(@needed.map {|d| DependencyRequest.new d, nil }).tsort.map(&:payload).compact
|
||||
Gem::Molinillo::Resolver.new(self, self).resolve(@needed.map {|d| DependencyRequest.new d, nil }).tsort.filter_map(&:payload)
|
||||
rescue Gem::Molinillo::VersionConflict => e
|
||||
conflict = e.conflicts.values.first
|
||||
raise Gem::DependencyResolutionError, Conflict.new(conflict.requirement_trees.first.first, conflict.existing, conflict.requirement)
|
||||
|
@ -201,7 +201,7 @@ class Gem::Source::Git < Gem::Source
|
||||
return [] unless install_dir
|
||||
|
||||
Dir.chdir install_dir do
|
||||
Dir["{,*,*/*}.gemspec"].map do |spec_file|
|
||||
Dir["{,*,*/*}.gemspec"].filter_map do |spec_file|
|
||||
directory = File.dirname spec_file
|
||||
file = File.basename spec_file
|
||||
|
||||
@ -218,7 +218,7 @@ class Gem::Source::Git < Gem::Source
|
||||
end
|
||||
spec
|
||||
end
|
||||
end.compact
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -66,7 +66,7 @@ class Endpoint < Sinatra::Base
|
||||
Marshal.load(File.binread(gem_repo.join(filename)))
|
||||
end.inject(:+)
|
||||
|
||||
all_specs.map do |name, version, platform|
|
||||
all_specs.filter_map do |name, version, platform|
|
||||
spec = load_spec(name, version, platform, gem_repo)
|
||||
next unless gem_names.include?(spec.name)
|
||||
{
|
||||
@ -77,7 +77,7 @@ class Endpoint < Sinatra::Base
|
||||
[dep.name, dep.requirement.requirements.map {|a| a.join(" ") }.join(", ")]
|
||||
end,
|
||||
}
|
||||
end.compact
|
||||
end
|
||||
end
|
||||
|
||||
def load_spec(name, version, platform, gem_repo)
|
||||
|
@ -116,7 +116,7 @@ module Spec
|
||||
source = opts.delete(:source)
|
||||
groups = Array(opts.delete(:groups)).map(&:inspect).join(", ")
|
||||
opts[:raise_on_error] = false
|
||||
@errors = names.map do |full_name|
|
||||
@errors = names.filter_map do |full_name|
|
||||
name, version, platform = full_name.split(/\s+/)
|
||||
platform ||= "ruby"
|
||||
require_path = name.tr("-", "/")
|
||||
@ -159,7 +159,7 @@ module Spec
|
||||
next "Expected #{name} (#{version}) to be installed from `#{source}`, was actually from `#{actual_source}`"
|
||||
end
|
||||
next "Command to check for inclusion of gem #{full_name} failed"
|
||||
end.compact
|
||||
end
|
||||
|
||||
@errors.empty?
|
||||
end
|
||||
@ -168,7 +168,7 @@ module Spec
|
||||
opts = names.last.is_a?(Hash) ? names.pop : {}
|
||||
groups = Array(opts.delete(:groups)).map(&:inspect).join(", ")
|
||||
opts[:raise_on_error] = false
|
||||
@errors = names.map do |name|
|
||||
@errors = names.filter_map do |name|
|
||||
name, version = name.split(/\s+/, 2)
|
||||
ruby <<-R, opts
|
||||
begin
|
||||
@ -194,7 +194,7 @@ module Spec
|
||||
next "command to check version of #{name} installed failed" unless exitstatus == 64
|
||||
next "expected #{name} to not be installed, but it was" if version.nil?
|
||||
next "expected #{name} (#{version}) not to be installed, but it was"
|
||||
end.compact
|
||||
end
|
||||
|
||||
@errors.empty?
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user