Skip to content

Commit

Permalink
Optimize memory usage
Browse files Browse the repository at this point in the history
  • Loading branch information
fatkodima authored and marcandre committed Oct 26, 2020
1 parent 3ebc79f commit 291aec7
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 7 deletions.
4 changes: 3 additions & 1 deletion lib/rubocop/cop/corrector.rb
Expand Up @@ -9,6 +9,8 @@ module Cop
# The nodes modified by the corrections should be part of the
# AST of the source_buffer.
class Corrector < ::Parser::Source::TreeRewriter
NOOP_CONSUMER = ->(diagnostic) {} # noop

# @param source [Parser::Source::Buffer, or anything
# leading to one via `(processed_source.)buffer`]
#
Expand All @@ -23,7 +25,7 @@ def initialize(source)
)

# Don't print warnings to stderr if corrections conflict with each other
diagnostics.consumer = ->(diagnostic) {} # noop
diagnostics.consumer = NOOP_CONSUMER
end

alias rewrite process # Legacy
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/mixin/line_length_help.rb
Expand Up @@ -57,7 +57,7 @@ def match_uris(string)
def indentation_difference(line)
return 0 unless tab_indentation_width

line.match(/^\t*/)[0].size * (tab_indentation_width - 1)
(line.index(/[^\t]/) || 0) * (tab_indentation_width - 1)
end

def tab_indentation_width
Expand Down
3 changes: 2 additions & 1 deletion lib/rubocop/cop/naming/predicate_name.rb
Expand Up @@ -67,7 +67,8 @@ def on_def(node)
private

def allowed_method_name?(method_name, prefix)
!method_name.match?(/^#{prefix}[^0-9]/) ||
!(method_name.start_with?(prefix) && # cheap check to avoid allocating Regexp
method_name.match?(/^#{prefix}[^0-9]/)) ||
method_name == expected_name(method_name, prefix) ||
method_name.end_with?('=') ||
allowed_method?(method_name)
Expand Down
3 changes: 3 additions & 0 deletions lib/rubocop/cop/style/semicolon.rb
Expand Up @@ -70,6 +70,9 @@ def on_begin(node) # rubocop:todo Metrics/CyclomaticComplexity
private

def check_for_line_terminator_or_opener
# Make the obvious check first
return unless @processed_source.raw_source.include?(';')

each_semicolon { |line, column| convention_on(line, column, true) }
end

Expand Down
7 changes: 6 additions & 1 deletion lib/rubocop/cop/team.rb
Expand Up @@ -99,7 +99,12 @@ def forces
def self.forces_for(cops)
needed = Hash.new { |h, k| h[k] = [] }
cops.each do |cop|
Array(cop.class.joining_forces).each { |force| needed[force] << cop }
forces = cop.class.joining_forces
if forces.is_a?(Array)
forces.each { |force| needed[force] << cop }
elsif forces
needed[forces] << cop
end
end

needed.map do |force_class, joining_cops|
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/util.rb
Expand Up @@ -62,7 +62,7 @@ def on_node(syms, sexp, excludes = [], &block)
end

def begins_its_line?(range)
(range.source_line =~ /\S/) == range.column
range.source_line.index(/\S/) == range.column
end

# Returns, for example, a bare `if` node if the given node is an `if`
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/magic_comment.rb
Expand Up @@ -194,7 +194,7 @@ def frozen_string_literal; end
class SimpleComment < MagicComment
# Match `encoding` or `coding`
def encoding
extract(/\A\s*\#.*\b(?:en)?coding: (#{TOKEN})/i)
extract(/\A\s*\#.*\b(?:en)?coding: (#{TOKEN})/io)
end

private
Expand All @@ -207,7 +207,7 @@ def encoding
# Case-insensitive and dashes/underscores are acceptable.
# @see https://git.io/vM7Mg
def extract_frozen_string_literal
extract(/\A\s*#\s*frozen[_-]string[_-]literal:\s*(#{TOKEN})\s*\z/i)
extract(/\A\s*#\s*frozen[_-]string[_-]literal:\s*(#{TOKEN})\s*\z/io)
end
end
end
Expand Down

0 comments on commit 291aec7

Please sign in to comment.