Skip to content

Commit

Permalink
Re-use URI parser object for performance improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
hsbt authored and dentarg committed Aug 23, 2024
1 parent c1aa039 commit 471de35
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion mustermann/lib/mustermann/ast/translator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,19 @@ def decorator_for(node)
result
end

# @return [URI::RFC2396_Parser] URI::RFC2396 parser
# @!visibility private
def uri_parser
if defined?(URI::RFC2396_PARSER)
URI::RFC2396_PARSER
else
@uri_parser ||= URI::RFC2396_Parser.new
end
end

# @return [String] escaped character
# @!visibility private
def escape(char, parser: URI::RFC2396_Parser.new, escape: URI::RFC2396_Parser.new.regexp[:UNSAFE], also_escape: nil)
def escape(char, parser: uri_parser, escape: uri_parser.regexp[:UNSAFE], also_escape: nil)
escape = Regexp.union(also_escape, escape) if also_escape
char.to_s =~ escape ? parser.escape(char, Regexp.union(*escape)) : char
end
Expand Down

0 comments on commit 471de35

Please sign in to comment.