From 4caa65349c360866ba7d869252394f69a5f6a769 Mon Sep 17 00:00:00 2001 From: pavel Date: Tue, 1 Oct 2019 12:54:43 +0200 Subject: [PATCH] optimize source maps --- lib/sprockets/source_map_utils.rb | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/sprockets/source_map_utils.rb b/lib/sprockets/source_map_utils.rb index ee216b342..61b9463e3 100644 --- a/lib/sprockets/source_map_utils.rb +++ b/lib/sprockets/source_map_utils.rb @@ -428,21 +428,23 @@ def vlq_encode(ary) # Returns an Array of Integers. def vlq_decode(str) result = [] - chars = str.split('') - while chars.any? - vlq = 0 - shift = 0 - continuation = true - while continuation - char = chars.shift - raise ArgumentError unless char - digit = BASE64_VALUES[char] - continuation = false if (digit & VLQ_CONTINUATION_BIT) == 0 - digit &= VLQ_BASE_MASK - vlq += digit << shift + shift = 0 + value = 0 + i = 0 + + while i < str.size do + digit = BASE64_VALUES[str[i]] + raise ArgumentError unless digit + continuation = (digit & VLQ_CONTINUATION_BIT) != 0 + digit &= VLQ_CONTINUATION_BIT - 1 + value += digit << shift + if continuation shift += VLQ_BASE_SHIFT + else + result << ((value & 1) == 1 ? -(value >> 1) : value >> 1) + value = shift = 0 end - result << (vlq & 1 == 1 ? -(vlq >> 1) : vlq >> 1) + i += 1 end result end