Socket
Socket
Sign inDemoInstall

sourcemap-codec

Package Overview
Dependencies
0
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.4.7 to 1.4.8

4

CHANGELOG.md
# sourcemap-codec changelog
## 1.4.8
* Performance boost ([#80](https://github.com/Rich-Harris/sourcemap-codec/pull/80))
## 1.4.7

@@ -4,0 +8,0 @@

69

dist/sourcemap-codec.es.js

@@ -7,26 +7,24 @@ var charToInteger = {};

function decode(mappings) {
var generatedCodeColumn = 0; // first field
var sourceFileIndex = 0; // second field
var sourceCodeLine = 0; // third field
var sourceCodeColumn = 0; // fourth field
var nameIndex = 0; // fifth field
var decoded = [];
var line = [];
var segment = [];
for (var i = 0, j = 0, shift = 0, value = 0, len = mappings.length; i < len; i++) {
var segment = [
0,
0,
0,
0,
0,
];
var j = 0;
for (var i = 0, shift = 0, value = 0; i < mappings.length; i++) {
var c = mappings.charCodeAt(i);
if (c === 44) { // ","
if (segment.length)
line.push(segment);
segment = [];
segmentify(line, segment, j);
j = 0;
}
else if (c === 59) { // ";"
if (segment.length)
line.push(segment);
segment = [];
segmentify(line, segment, j);
j = 0;
decoded.push(line);
line = [];
generatedCodeColumn = 0;
segment[0] = 0;
}

@@ -48,26 +46,5 @@ else {

if (shouldNegate) {
value = -value;
if (value === 0)
value = -0x80000000;
value = value === 0 ? -0x80000000 : -value;
}
if (j == 0) {
generatedCodeColumn += value;
segment.push(generatedCodeColumn);
}
else if (j === 1) {
sourceFileIndex += value;
segment.push(sourceFileIndex);
}
else if (j === 2) {
sourceCodeLine += value;
segment.push(sourceCodeLine);
}
else if (j === 3) {
sourceCodeColumn += value;
segment.push(sourceCodeColumn);
}
else if (j === 4) {
nameIndex += value;
segment.push(nameIndex);
}
segment[j] += value;
j++;

@@ -78,7 +55,21 @@ value = shift = 0; // reset

}
if (segment.length)
line.push(segment);
segmentify(line, segment, j);
decoded.push(line);
return decoded;
}
function segmentify(line, segment, j) {
// This looks ugly, but we're creating specialized arrays with a specific
// length. This is much faster than creating a new array (which v8 expands to
// a capacity of 17 after pushing the first item), or slicing out a subarray
// (which is slow). Length 4 is assumed to be the most frequent, followed by
// length 5 (since not everything will have an associated name), followed by
// length 1 (it's probably rare for a source substring to not have an
// associated segment data).
if (j === 4)
line.push([segment[0], segment[1], segment[2], segment[3]]);
else if (j === 5)
line.push([segment[0], segment[1], segment[2], segment[3], segment[4]]);
else if (j === 1)
line.push([segment[0]]);
}
function encode(decoded) {

@@ -85,0 +76,0 @@ var sourceFileIndex = 0; // second field

@@ -13,26 +13,24 @@ (function (global, factory) {

function decode(mappings) {
var generatedCodeColumn = 0; // first field
var sourceFileIndex = 0; // second field
var sourceCodeLine = 0; // third field
var sourceCodeColumn = 0; // fourth field
var nameIndex = 0; // fifth field
var decoded = [];
var line = [];
var segment = [];
for (var i = 0, j = 0, shift = 0, value = 0, len = mappings.length; i < len; i++) {
var segment = [
0,
0,
0,
0,
0,
];
var j = 0;
for (var i = 0, shift = 0, value = 0; i < mappings.length; i++) {
var c = mappings.charCodeAt(i);
if (c === 44) { // ","
if (segment.length)
line.push(segment);
segment = [];
segmentify(line, segment, j);
j = 0;
}
else if (c === 59) { // ";"
if (segment.length)
line.push(segment);
segment = [];
segmentify(line, segment, j);
j = 0;
decoded.push(line);
line = [];
generatedCodeColumn = 0;
segment[0] = 0;
}

@@ -54,26 +52,5 @@ else {

if (shouldNegate) {
value = -value;
if (value === 0)
value = -0x80000000;
value = value === 0 ? -0x80000000 : -value;
}
if (j == 0) {
generatedCodeColumn += value;
segment.push(generatedCodeColumn);
}
else if (j === 1) {
sourceFileIndex += value;
segment.push(sourceFileIndex);
}
else if (j === 2) {
sourceCodeLine += value;
segment.push(sourceCodeLine);
}
else if (j === 3) {
sourceCodeColumn += value;
segment.push(sourceCodeColumn);
}
else if (j === 4) {
nameIndex += value;
segment.push(nameIndex);
}
segment[j] += value;
j++;

@@ -84,7 +61,21 @@ value = shift = 0; // reset

}
if (segment.length)
line.push(segment);
segmentify(line, segment, j);
decoded.push(line);
return decoded;
}
function segmentify(line, segment, j) {
// This looks ugly, but we're creating specialized arrays with a specific
// length. This is much faster than creating a new array (which v8 expands to
// a capacity of 17 after pushing the first item), or slicing out a subarray
// (which is slow). Length 4 is assumed to be the most frequent, followed by
// length 5 (since not everything will have an associated name), followed by
// length 1 (it's probably rare for a source substring to not have an
// associated segment data).
if (j === 4)
line.push([segment[0], segment[1], segment[2], segment[3]]);
else if (j === 5)
line.push([segment[0], segment[1], segment[2], segment[3], segment[4]]);
else if (j === 1)
line.push([segment[0]]);
}
function encode(decoded) {

@@ -91,0 +82,0 @@ var sourceFileIndex = 0; // second field

{
"name": "sourcemap-codec",
"version": "1.4.7",
"version": "1.4.8",
"description": "Encode/decode sourcemap mappings",

@@ -5,0 +5,0 @@ "main": "dist/sourcemap-codec.umd.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc