Skip to content

Commit

Permalink
Store parsed regexp in Node.
Browse files Browse the repository at this point in the history
We'll be adding references to the source to the nodes,
so I can't think of any other way to proceed that won't involve
unacceptable memory leaks.
  • Loading branch information
marcandre authored and bbatsov committed Oct 28, 2020
1 parent 49d8ccd commit 58c9474
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lib/rubocop/ext/regexp_node.rb
Expand Up @@ -10,15 +10,14 @@ def ANY.==(_)
end
private_constant :ANY

class << self
attr_reader :parsed_cache
end
@parsed_cache = {}

# @return [Regexp::Expression::Root, nil]
def parsed_tree
attr_reader :parsed_tree

def assign_properties(*)
super

str = with_interpolations_blanked
Ext::RegexpNode.parsed_cache[str] ||= begin
@parsed_tree = begin
Regexp::Parser.parse(str, options: options)
rescue StandardError
nil
Expand Down

0 comments on commit 58c9474

Please sign in to comment.