Skip to content

Commit a20a869

Browse files
Merge pull request #9230 from mhashizume/maint/main/new-performance-cops
Fix performance cops
2 parents aa71d29 + 292f55c commit a20a869

File tree

20 files changed

+41
-43
lines changed

20 files changed

+41
-43
lines changed

lib/puppet/environments.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,9 @@ def validated_directory(envdir)
269269
def valid_environment_names
270270
return [] unless Puppet::FileSystem.directory?(@environment_dir)
271271

272-
Puppet::FileSystem.children(@environment_dir).map do |child|
272+
Puppet::FileSystem.children(@environment_dir).filter_map do |child|
273273
Puppet::FileSystem.basename_string(child).intern if validated_directory(child)
274-
end.compact
274+
end
275275
end
276276
end
277277

lib/puppet/external/dot.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,10 @@ def to_s(t = '')
208208
t + $tab + '"' + "\n"
209209

210210
t + "#{@name} [\n" +
211-
@options.to_a.collect { |i|
211+
@options.to_a.filter_map { |i|
212212
i[1] && i[0] != 'label' ?
213213
t + $tab + "#{i[0]} = #{i[1]}" : nil
214-
}.compact.join(",\n") + (label != '' ? ",\n" : "\n") +
214+
}.join(",\n") + (label != '' ? ",\n" : "\n") +
215215
label +
216216
t + "]\n"
217217
end
@@ -252,11 +252,11 @@ def pop
252252
def to_s(t = '')
253253
hdr = t + "#{@dot_string} #{@name} {\n"
254254

255-
options = @options.to_a.collect { |name, val|
255+
options = @options.to_a.filter_map { |name, val|
256256
val && name != 'label' ?
257257
t + $tab + "#{name} = #{val}" :
258258
name ? t + $tab + "#{name} = \"#{val}\"" : nil
259-
}.compact.join("\n") + "\n"
259+
}.join("\n") + "\n"
260260

261261
nodes = @nodes.collect { |i|
262262
i.to_s(t + $tab)
@@ -291,11 +291,11 @@ def edge_link
291291

292292
def to_s(t = '')
293293
t + "#{@from} #{edge_link} #{to} [\n" +
294-
@options.to_a.collect { |i|
294+
@options.to_a.filter_map { |i|
295295
i[1] && i[0] != 'label' ?
296296
t + $tab + "#{i[0]} = #{i[1]}" :
297297
i[1] ? t + $tab + "#{i[0]} = \"#{i[1]}\"" : nil
298-
}.compact.join("\n") + "\n#{t}]\n"
298+
}.join("\n") + "\n#{t}]\n"
299299
end
300300
end
301301

lib/puppet/face/module/list.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def warn_unmet_dependencies(environment)
211211
# └── puppetlabs-sqlite (v0.0.1)
212212
#
213213
def list_build_tree(list, ancestors = [], parent = nil, params = {})
214-
list.map do |mod|
214+
list.filter_map do |mod|
215215
next if @seen[(mod.forge_name or mod.name)]
216216

217217
node = list_build_node(mod, parent, params)
@@ -232,7 +232,7 @@ def list_build_tree(list, ancestors = [], parent = nil, params = {})
232232
end
233233

234234
node
235-
end.compact
235+
end
236236
end
237237

238238
# Prepare a module object for print in a tree view. Each node in the tree

lib/puppet/module_tool.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def self.build_tree(mods, dir)
103103
mod[:text] += " [#{mod[:path]}]" unless mod[:path].to_s == dir.to_s
104104

105105
deps = (mod[:dependencies] || [])
106-
deps.sort! { |a, b| a[:name] <=> b[:name] }
106+
deps.sort_by! { |a| a[:name] }
107107
build_tree(deps, dir)
108108
end
109109
end

lib/puppet/module_tool/applications/upgrader.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ def build_install_graph(release, installed, graphed = [])
257257

258258
graphed << release
259259

260-
dependencies = release.dependencies.values.map do |deps|
260+
dependencies = release.dependencies.values.filter_map do |deps|
261261
dep = (deps & installed).first
262262
if dep == installed_modules[dep.name]
263263
next
@@ -266,7 +266,7 @@ def build_install_graph(release, installed, graphed = [])
266266
if dep && !graphed.include?(dep)
267267
build_install_graph(dep, installed, graphed)
268268
end
269-
end.compact
269+
end
270270

271271
return {
272272
:release => release,

lib/puppet/module_tool/shared_behaviors.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def get_remote_constraints(forge)
3939
releases.each do |rel|
4040
semver = SemanticPuppet::Version.parse(rel['version']) rescue SemanticPuppet::Version::MIN
4141
@versions[mod_name] << { :vstring => rel['version'], :semver => semver }
42-
@versions[mod_name].sort! { |a, b| a[:semver] <=> b[:semver] }
42+
@versions[mod_name].sort_by! { |a| a[:semver] }
4343
@urls["#{mod_name}@#{rel['version']}"] = rel['file']
4444
d = @remote["#{mod_name}@#{rel['version']}"]
4545
(rel['dependencies'] || []).each do |name, conditions|
@@ -67,7 +67,7 @@ def annotated_version(mod, versions)
6767
end
6868

6969
def resolve_constraints(dependencies, source = [{ :name => :you }], seen = {}, action = @action)
70-
dependencies = dependencies.map do |mod, range|
70+
dependencies = dependencies.filter_map do |mod, range|
7171
source.last[:dependency] = range
7272

7373
@conditions[mod] << {
@@ -138,7 +138,7 @@ def resolve_constraints(dependencies, source = [{ :name => :you }], seen = {}, a
138138
:path => action == :install ? @options[:target_dir] : (@installed[mod].empty? ? @options[:target_dir] : @installed[mod].first.modulepath),
139139
:dependencies => []
140140
}
141-
end.compact
141+
end
142142
dependencies.each do |mod|
143143
deps = @remote["#{mod[:module]}@#{mod[:version][:vstring]}"].sort_by(&:first)
144144
mod[:dependencies] = resolve_constraints(deps, source + [{ :name => mod[:module], :version => mod[:version][:vstring] }], seen, :install)

lib/puppet/network/format_handler.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,13 @@ def self.format_to_canonical_name(format)
8686
def self.most_suitable_formats_for(accepted, supported)
8787
accepted.collect do |format|
8888
format.to_s.sub(/;q=.*$/, '')
89-
end.collect do |format|
89+
end.filter_map do |format|
9090
if format == ALL_MEDIA_TYPES
9191
supported.first
9292
else
9393
format_to_canonical_name_or_nil(format)
9494
end
95-
end.compact.find_all do |format|
95+
end.find_all do |format|
9696
supported.include?(format)
9797
end.collect do |format|
9898
format_for(format)

lib/puppet/network/http/handler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def register(routes)
1919
# There's got to be a simpler way to do this, right?
2020
dupes = {}
2121
routes.each { |r| dupes[r.path_matcher] = (dupes[r.path_matcher] || 0) + 1 }
22-
dupes = dupes.collect { |pm, count| pm if count > 1 }.compact
22+
dupes = dupes.filter_map { |pm, count| pm if count > 1 }
2323
if dupes.count > 0
2424
raise ArgumentError, _("Given multiple routes with identical path regexes: %{regexes}") % { regexes: dupes.map { |rgx| rgx.inspect }.join(', ') }
2525
end

lib/puppet/node/environment.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,14 +365,14 @@ def modules
365365
end
366366
end
367367

368-
@modules = module_references.collect do |reference|
368+
@modules = module_references.filter_map do |reference|
369369
begin
370370
Puppet::Module.new(reference[:name], reference[:path], self)
371371
rescue Puppet::Module::Error => e
372372
Puppet.log_exception(e)
373373
nil
374374
end
375-
end.compact
375+
end
376376
end
377377
@modules
378378
end

lib/puppet/parser/functions/create_resources.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,15 @@
100100
virtual, exported,
101101
type_name,
102102
resource_titles,
103-
defaults.merge(params).map do |name, value|
103+
defaults.merge(params).filter_map do |name, value|
104104
value = nil if value == :undef
105105
Puppet::Parser::Resource::Param.new(
106106
:name => name,
107107
:value => value, # wide open to various data types, must be correct
108108
:source => self.source, # TODO: support :line => line, :file => file,
109109
:add => false
110110
)
111-
end.compact
111+
end
112112
)
113113
end.flatten.compact
114114
end

0 commit comments

Comments
 (0)