Skip to content

Commit

Permalink
optimize source maps
Browse files Browse the repository at this point in the history
  • Loading branch information
ahorek committed Oct 1, 2019
1 parent 365036d commit 4caa653
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions lib/sprockets/source_map_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4caa653

Please sign in to comment.