Skip to content

Commit

Permalink
Simplify and optimize.
Browse files Browse the repository at this point in the history
This reduces memory allocation from 19MB to 1.9MB (when run on cop/mixin).
Main issue remains that it is called way too many times
  • Loading branch information
marcandre committed Jul 13, 2020
1 parent f93da20 commit e9abe2e
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/rubocop/ast/node_pattern.rb
Expand Up @@ -133,6 +133,8 @@ class Compiler
PARAM_NUMBER = /%\d*/.freeze

SEPARATORS = /\s+/.freeze
ONLY_SEPARATOR = /\A#{SEPARATORS}\Z/.freeze

TOKENS = Regexp.union(META, PARAM_CONST, KEYWORD_NAME, PARAM_NUMBER, NUMBER,
METHOD_NAME, SYMBOL, STRING)

Expand Down Expand Up @@ -783,7 +785,7 @@ def substitute_cur_node(code, cur_node, first_cur_node: cur_node)
end

def self.tokens(pattern)
pattern.scan(TOKEN).reject { |token| token =~ /\A#{SEPARATORS}\Z/ }
pattern.scan(TOKEN).grep_v(ONLY_SEPARATOR)
end

def def_helper(base, method_name, **defaults)
Expand Down

0 comments on commit e9abe2e

Please sign in to comment.