Skip to content

Commit

Permalink
Improve RFC3986 decoding performance
Browse files Browse the repository at this point in the history
  • Loading branch information
ntkme committed Jul 5, 2024
1 parent 0608e6c commit e2aa995
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/sassc/embedded.rb
Original file line number Diff line number Diff line change
Expand Up @@ -576,16 +576,16 @@ def parse(...)
}
.each do |symbol, preserve_escaped|
regexp = /%[0-9A-Fa-f]{2}/o
if preserve_escaped.nil?
if preserve_escaped.nil? || preserve_escaped.empty?
define_method(symbol) do |str|
str.gsub(regexp) do |match|
[match[1, 2]].pack('H2')
[match.reverse!].pack('h2')
end.force_encoding(str.encoding)
end
else
define_method(symbol) do |str|
str.gsub(regexp) do |match|
decoded = [match[1, 2]].pack('H2')
decoded = [match.reverse].pack('h2')
preserve_escaped.include?(decoded) ? match : decoded
end.force_encoding(str.encoding)
end
Expand Down

0 comments on commit e2aa995

Please sign in to comment.