Enable `Performance/ChainArrayAllocation` cop (#8404)

Merge pull request 8404
This commit is contained in:
Ashwin Maroli 2020-09-30 12:19:12 +05:30 committed by GitHub
parent 166796c448
commit f7292ec9cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 17 additions and 15 deletions

View File

@ -160,6 +160,8 @@ Performance/AncestorsInclude:
Enabled: false Enabled: false
Performance/BigDecimalWithNumericArgument: Performance/BigDecimalWithNumericArgument:
Enabled: true Enabled: true
Performance/ChainArrayAllocation:
Enabled: true
Performance/RedundantSortBlock: Performance/RedundantSortBlock:
Enabled: true Enabled: true
Performance/RedundantStringChars: Performance/RedundantStringChars:

View File

@ -139,12 +139,8 @@ module Jekyll
# Returns an Array of strings which represent method-specific keys. # Returns an Array of strings which represent method-specific keys.
def content_methods def content_methods
@content_methods ||= ( @content_methods ||= (
self.class.instance_methods \ self.class.instance_methods - Jekyll::Drops::Drop.instance_methods - NON_CONTENT_METHODS
- Jekyll::Drops::Drop.instance_methods \ ).map!(&:to_s).tap { |result| result.reject! { |method| method.end_with?("=") } }
- NON_CONTENT_METHODS
).map(&:to_s).reject do |method|
method.end_with?("=")
end
end end
# Check if key exists in Drop # Check if key exists in Drop

View File

@ -76,13 +76,16 @@ module Jekyll
parts = [sanitized_baseurl, input] parts = [sanitized_baseurl, input]
Addressable::URI.parse( Addressable::URI.parse(
parts.compact.map { |part| ensure_leading_slash(part.to_s) }.join parts.map! { |part| ensure_leading_slash(part.to_s) }.join
).normalize.to_s ).normalize.to_s
end end
def sanitized_baseurl def sanitized_baseurl
site = @context.registers[:site] site = @context.registers[:site]
site.config["baseurl"].to_s.chomp("/") baseurl = site.config["baseurl"]
return "" if baseurl.nil?
baseurl.to_s.chomp("/")
end end
def ensure_leading_slash(input) def ensure_leading_slash(input)

View File

@ -223,7 +223,7 @@ module Jekyll
Jekyll.logger.warn set.to_s Jekyll.logger.warn set.to_s
nil nil
end end
end.compact end.tap(&:compact!)
end end
# Sanitizes the given path by removing a leading slash # Sanitizes the given path by removing a leading slash

View File

@ -57,7 +57,7 @@ module Jekyll
Document.new(path, Document.new(path,
:site => @site, :site => @site,
:collection => @site.posts) :collection => @site.posts)
end.reject(&:nil?) end.tap(&:compact!)
end end
private private

View File

@ -46,7 +46,7 @@ module Jekyll
end end
def most_recent_posts def most_recent_posts
@most_recent_posts ||= (site.posts.docs.last(11).reverse - [post]).first(10) @most_recent_posts ||= (site.posts.docs.last(11).reverse! - [post]).first(10)
end end
end end
end end

View File

@ -36,7 +36,7 @@ module Jekyll
# #
# Returns Array of Converter instances. # Returns Array of Converter instances.
def converters def converters
@converters ||= site.converters.select { |c| c.matches(document.extname) }.sort @converters ||= site.converters.select { |c| c.matches(document.extname) }.tap(&:sort!)
end end
# Determine the extname the outputted file should have # Determine the extname the outputted file should have
@ -255,7 +255,7 @@ module Jekyll
def output_exts def output_exts
@output_exts ||= converters.map do |c| @output_exts ||= converters.map do |c|
c.output_ext(document.extname) c.output_ext(document.extname)
end.compact end.tap(&:compact!)
end end
def liquid_options def liquid_options

View File

@ -310,8 +310,9 @@ module Jekyll
# passed in as argument. # passed in as argument.
def instantiate_subclasses(klass) def instantiate_subclasses(klass)
klass.descendants.select { |c| !safe || c.safe }.sort.map do |c| klass.descendants.select { |c| !safe || c.safe }.tap do |result|
c.new(config) result.sort!
result.map! { |c| c.new(config) }
end end
end end