aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/scssphp/scssphp/src/SourceMap/Base64VLQ.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/scssphp/scssphp/src/SourceMap/Base64VLQ.php')
-rw-r--r--vendor/scssphp/scssphp/src/SourceMap/Base64VLQ.php70
1 files changed, 4 insertions, 66 deletions
diff --git a/vendor/scssphp/scssphp/src/SourceMap/Base64VLQ.php b/vendor/scssphp/scssphp/src/SourceMap/Base64VLQ.php
index 2a5210c68..166466777 100644
--- a/vendor/scssphp/scssphp/src/SourceMap/Base64VLQ.php
+++ b/vendor/scssphp/scssphp/src/SourceMap/Base64VLQ.php
@@ -37,7 +37,7 @@ namespace ScssPhp\ScssPhp\SourceMap;
*
* @internal
*/
-class Base64VLQ
+final class Base64VLQ
{
// A Base64 VLQ digit can represent 5 bits, so it is base-32.
const VLQ_BASE_SHIFT = 5;
@@ -50,12 +50,8 @@ class Base64VLQ
/**
* Returns the VLQ encoded value.
- *
- * @param int $value
- *
- * @return string
*/
- public static function encode($value)
+ public static function encode(int $value): string
{
$encoded = '';
$vlq = self::toVLQSigned($value);
@@ -77,75 +73,17 @@ class Base64VLQ
}
/**
- * Decodes VLQValue.
- *
- * @param string $str
- * @param int $index
- *
- * @return int
- */
- public static function decode($str, &$index)
- {
- $result = 0;
- $shift = 0;
-
- do {
- $c = $str[$index++];
- $digit = Base64::decode($c);
- $continuation = ($digit & self::VLQ_CONTINUATION_BIT) != 0;
- $digit &= self::VLQ_BASE_MASK;
- $result = $result + ($digit << $shift);
- $shift = $shift + self::VLQ_BASE_SHIFT;
- } while ($continuation);
-
- return self::fromVLQSigned($result);
- }
-
- /**
* Converts from a two-complement value to a value where the sign bit is
* is placed in the least significant bit. For example, as decimals:
* 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
* 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
- *
- * @param int $value
- *
- * @return int
*/
- private static function toVLQSigned($value)
+ private static function toVLQSigned(int $value): int
{
if ($value < 0) {
return ((-$value) << 1) + 1;
}
- return ($value << 1) + 0;
- }
-
- /**
- * Converts to a two-complement value from a value where the sign bit is
- * is placed in the least significant bit. For example, as decimals:
- * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
- * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
- *
- * @param int $value
- *
- * @return int
- */
- private static function fromVLQSigned($value)
- {
- $negate = ($value & 1) === 1;
-
- //$value >>>= 1; // unsigned right shift
- $value = ($value >> 1) & PHP_INT_MAX;
-
- if (! $negate) {
- return $value;
- }
-
- // We need to OR 0x80000000 here to ensure the 32nd bit (the sign bit) is
- // always set for negative numbers. If `value` were 1, (meaning `negate` is
- // true and all other bits were zeros), `value` would now be 0. -0 is just
- // 0, and doesn't flip the 32nd bit as intended. All positive numbers will
- // successfully flip the 32nd bit without issue, so it's a noop for them.
- return -$value | 0x80000000;
+ return $value << 1;
}
}