From e2aa9954e416c945ca7d3b907f694860ee140197 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=AA=E3=81=A4=E3=81=8D?= Date: Fri, 5 Jul 2024 03:13:56 -0700 Subject: [PATCH] Improve RFC3986 decoding performance --- lib/sassc/embedded.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/sassc/embedded.rb b/lib/sassc/embedded.rb index 1281f39..4365c96 100644 --- a/lib/sassc/embedded.rb +++ b/lib/sassc/embedded.rb @@ -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