@jridgewell/sourcemap-codec
Advanced tools
Comparing version 1.4.11 to 1.4.12
@@ -11,11 +11,11 @@ (function (global, factory) { | ||
const intToChar = new Uint8Array(64); // 64 possible chars. | ||
const charToInteger = new Uint8Array(128); // z is 122 in ASCII | ||
const charToInt = new Uint8Array(128); // z is 122 in ASCII | ||
for (let i = 0; i < chars.length; i++) { | ||
const c = chars.charCodeAt(i); | ||
charToInteger[c] = i; | ||
intToChar[i] = c; | ||
charToInt[c] = i; | ||
} | ||
// Provide a fallback for older environments. | ||
const td = typeof TextDecoder !== 'undefined' | ||
? new TextDecoder() | ||
? /* #__PURE__ */ new TextDecoder() | ||
: typeof Buffer !== 'undefined' | ||
@@ -40,21 +40,12 @@ ? { | ||
const decoded = []; | ||
let line = []; | ||
let sorted = true; | ||
let lastCol = 0; | ||
for (let i = 0; i < mappings.length;) { | ||
const c = mappings.charCodeAt(i); | ||
if (c === comma) { | ||
i++; | ||
} | ||
else if (c === semicolon) { | ||
state[0] = lastCol = 0; | ||
if (!sorted) | ||
sort(line); | ||
sorted = true; | ||
decoded.push(line); | ||
line = []; | ||
i++; | ||
} | ||
else { | ||
i = decodeInteger(mappings, i, state, 0); // generatedCodeColumn | ||
let index = 0; | ||
do { | ||
const semi = indexOf(mappings, index); | ||
const line = []; | ||
let sorted = true; | ||
let lastCol = 0; | ||
state[0] = 0; | ||
for (let i = index; i < semi; i++) { | ||
let seg; | ||
i = decodeInteger(mappings, i, state, 0); // genColumn | ||
const col = state[0]; | ||
@@ -64,22 +55,31 @@ if (col < lastCol) | ||
lastCol = col; | ||
if (!hasMoreSegments(mappings, i)) { | ||
line.push([col]); | ||
continue; | ||
if (hasMoreVlq(mappings, i, semi)) { | ||
i = decodeInteger(mappings, i, state, 1); // sourcesIndex | ||
i = decodeInteger(mappings, i, state, 2); // sourceLine | ||
i = decodeInteger(mappings, i, state, 3); // sourceColumn | ||
if (hasMoreVlq(mappings, i, semi)) { | ||
i = decodeInteger(mappings, i, state, 4); // namesIndex | ||
seg = [col, state[1], state[2], state[3], state[4]]; | ||
} | ||
else { | ||
seg = [col, state[1], state[2], state[3]]; | ||
} | ||
} | ||
i = decodeInteger(mappings, i, state, 1); // sourceFileIndex | ||
i = decodeInteger(mappings, i, state, 2); // sourceCodeLine | ||
i = decodeInteger(mappings, i, state, 3); // sourceCodeColumn | ||
if (!hasMoreSegments(mappings, i)) { | ||
line.push([col, state[1], state[2], state[3]]); | ||
continue; | ||
else { | ||
seg = [col]; | ||
} | ||
i = decodeInteger(mappings, i, state, 4); // nameIndex | ||
line.push([col, state[1], state[2], state[3], state[4]]); | ||
line.push(seg); | ||
} | ||
} | ||
if (!sorted) | ||
sort(line); | ||
decoded.push(line); | ||
if (!sorted) | ||
sort(line); | ||
decoded.push(line); | ||
index = semi + 1; | ||
} while (index <= mappings.length); | ||
return decoded; | ||
} | ||
function indexOf(mappings, index) { | ||
const len = mappings.length; | ||
const idx = index < len ? mappings.indexOf(';', index) : index; | ||
return idx === -1 ? len : idx; | ||
} | ||
function decodeInteger(mappings, pos, state, j) { | ||
@@ -91,3 +91,3 @@ let value = 0; | ||
const c = mappings.charCodeAt(pos++); | ||
integer = charToInteger[c]; | ||
integer = charToInt[c]; | ||
value |= (integer & 31) << shift; | ||
@@ -104,9 +104,6 @@ shift += 5; | ||
} | ||
function hasMoreSegments(mappings, i) { | ||
if (i >= mappings.length) | ||
function hasMoreVlq(mappings, i, length) { | ||
if (i >= length) | ||
return false; | ||
const c = mappings.charCodeAt(i); | ||
if (c === comma || c === semicolon) | ||
return false; | ||
return true; | ||
return mappings.charCodeAt(i) !== comma; | ||
} | ||
@@ -121,8 +118,15 @@ function sort(line) { | ||
const state = new Int32Array(5); | ||
let buf = new Uint8Array(1024); | ||
const bufLength = 1024 * 16; | ||
const subLength = bufLength - 36; | ||
const buf = new Uint8Array(bufLength); | ||
const sub = buf.subarray(0, subLength); | ||
let pos = 0; | ||
let out = ''; | ||
for (let i = 0; i < decoded.length; i++) { | ||
const line = decoded[i]; | ||
if (i > 0) { | ||
buf = reserve(buf, pos, 1); | ||
if (pos === bufLength) { | ||
out += td.decode(buf); | ||
pos = 0; | ||
} | ||
buf[pos++] = semicolon; | ||
@@ -137,25 +141,22 @@ } | ||
// may push a comma. | ||
buf = reserve(buf, pos, 36); | ||
if (pos > subLength) { | ||
out += td.decode(sub); | ||
buf.copyWithin(0, subLength, pos); | ||
pos -= subLength; | ||
} | ||
if (j > 0) | ||
buf[pos++] = comma; | ||
pos = encodeInteger(buf, pos, state, segment, 0); // generatedCodeColumn | ||
pos = encodeInteger(buf, pos, state, segment, 0); // genColumn | ||
if (segment.length === 1) | ||
continue; | ||
pos = encodeInteger(buf, pos, state, segment, 1); // sourceFileIndex | ||
pos = encodeInteger(buf, pos, state, segment, 2); // sourceCodeLine | ||
pos = encodeInteger(buf, pos, state, segment, 3); // sourceCodeColumn | ||
pos = encodeInteger(buf, pos, state, segment, 1); // sourcesIndex | ||
pos = encodeInteger(buf, pos, state, segment, 2); // sourceLine | ||
pos = encodeInteger(buf, pos, state, segment, 3); // sourceColumn | ||
if (segment.length === 4) | ||
continue; | ||
pos = encodeInteger(buf, pos, state, segment, 4); // nameIndex | ||
pos = encodeInteger(buf, pos, state, segment, 4); // namesIndex | ||
} | ||
} | ||
return td.decode(buf.subarray(0, pos)); | ||
return out + td.decode(buf.subarray(0, pos)); | ||
} | ||
function reserve(buf, pos, count) { | ||
if (buf.length > pos + count) | ||
return buf; | ||
const swap = new Uint8Array(buf.length * 2); | ||
swap.set(buf); | ||
return swap; | ||
} | ||
function encodeInteger(buf, pos, state, segment, j) { | ||
@@ -162,0 +163,0 @@ const next = segment[j]; |
@@ -6,1 +6,2 @@ export declare type SourceMapSegment = [number] | [number, number, number, number] | [number, number, number, number, number]; | ||
export declare function encode(decoded: SourceMapMappings): string; | ||
export declare function encode(decoded: Readonly<SourceMapMappings>): string; |
{ | ||
"name": "@jridgewell/sourcemap-codec", | ||
"version": "1.4.11", | ||
"version": "1.4.12", | ||
"description": "Encode/decode sourcemap mappings", | ||
@@ -24,4 +24,5 @@ "keywords": [ | ||
"scripts": { | ||
"benchmark": "run-s build:rollup benchmark:only", | ||
"benchmark:only": "node benchmark/index.js", | ||
"benchmark": "run-s build:rollup benchmark:*", | ||
"benchmark:install": "cd benchmark && npm install", | ||
"benchmark:only": "node --expose-gc benchmark/index.js", | ||
"build": "run-s -n build:*", | ||
@@ -28,0 +29,0 @@ "build:rollup": "rollup -c rollup.config.js", |
137
README.md
@@ -60,5 +60,142 @@ # sourcemap-codec | ||
## Benchmarks | ||
``` | ||
node v18.0.0 | ||
amp.js.map - 45120 segments | ||
Decode Memory Usage: | ||
@jridgewell/sourcemap-codec 5479160 bytes | ||
sourcemap-codec 5659336 bytes | ||
source-map-0.6.1 17144440 bytes | ||
source-map-0.8.0 6867424 bytes | ||
Smallest memory usage is @jridgewell/sourcemap-codec | ||
Decode speed: | ||
decode: @jridgewell/sourcemap-codec x 502 ops/sec ±1.03% (90 runs sampled) | ||
decode: sourcemap-codec x 445 ops/sec ±0.97% (92 runs sampled) | ||
decode: source-map-0.6.1 x 36.01 ops/sec ±1.64% (49 runs sampled) | ||
decode: source-map-0.8.0 x 367 ops/sec ±0.04% (95 runs sampled) | ||
Fastest is decode: @jridgewell/sourcemap-codec | ||
Encode Memory Usage: | ||
@jridgewell/sourcemap-codec 1261620 bytes | ||
sourcemap-codec 9119248 bytes | ||
source-map-0.6.1 8968560 bytes | ||
source-map-0.8.0 8952952 bytes | ||
Smallest memory usage is @jridgewell/sourcemap-codec | ||
Encode speed: | ||
encode: @jridgewell/sourcemap-codec x 738 ops/sec ±0.42% (98 runs sampled) | ||
encode: sourcemap-codec x 238 ops/sec ±0.73% (88 runs sampled) | ||
encode: source-map-0.6.1 x 162 ops/sec ±0.43% (84 runs sampled) | ||
encode: source-map-0.8.0 x 191 ops/sec ±0.34% (90 runs sampled) | ||
Fastest is encode: @jridgewell/sourcemap-codec | ||
*** | ||
babel.min.js.map - 347793 segments | ||
Decode Memory Usage: | ||
@jridgewell/sourcemap-codec 35338184 bytes | ||
sourcemap-codec 35922736 bytes | ||
source-map-0.6.1 62366360 bytes | ||
source-map-0.8.0 44337416 bytes | ||
Smallest memory usage is @jridgewell/sourcemap-codec | ||
Decode speed: | ||
decode: @jridgewell/sourcemap-codec x 40.35 ops/sec ±4.47% (54 runs sampled) | ||
decode: sourcemap-codec x 36.76 ops/sec ±3.67% (51 runs sampled) | ||
decode: source-map-0.6.1 x 4.44 ops/sec ±2.15% (16 runs sampled) | ||
decode: source-map-0.8.0 x 59.35 ops/sec ±0.05% (78 runs sampled) | ||
Fastest is decode: source-map-0.8.0 | ||
Encode Memory Usage: | ||
@jridgewell/sourcemap-codec 7212604 bytes | ||
sourcemap-codec 21421456 bytes | ||
source-map-0.6.1 25286888 bytes | ||
source-map-0.8.0 25498744 bytes | ||
Smallest memory usage is @jridgewell/sourcemap-codec | ||
Encode speed: | ||
encode: @jridgewell/sourcemap-codec x 112 ops/sec ±0.13% (84 runs sampled) | ||
encode: sourcemap-codec x 30.23 ops/sec ±2.76% (53 runs sampled) | ||
encode: source-map-0.6.1 x 19.43 ops/sec ±3.70% (37 runs sampled) | ||
encode: source-map-0.8.0 x 19.40 ops/sec ±3.26% (37 runs sampled) | ||
Fastest is encode: @jridgewell/sourcemap-codec | ||
*** | ||
preact.js.map - 1992 segments | ||
Decode Memory Usage: | ||
@jridgewell/sourcemap-codec 500272 bytes | ||
sourcemap-codec 516864 bytes | ||
source-map-0.6.1 1596672 bytes | ||
source-map-0.8.0 517272 bytes | ||
Smallest memory usage is @jridgewell/sourcemap-codec | ||
Decode speed: | ||
decode: @jridgewell/sourcemap-codec x 16,137 ops/sec ±0.17% (99 runs sampled) | ||
decode: sourcemap-codec x 12,139 ops/sec ±0.13% (99 runs sampled) | ||
decode: source-map-0.6.1 x 1,264 ops/sec ±0.12% (100 runs sampled) | ||
decode: source-map-0.8.0 x 9,894 ops/sec ±0.08% (101 runs sampled) | ||
Fastest is decode: @jridgewell/sourcemap-codec | ||
Encode Memory Usage: | ||
@jridgewell/sourcemap-codec 321026 bytes | ||
sourcemap-codec 830832 bytes | ||
source-map-0.6.1 586608 bytes | ||
source-map-0.8.0 586680 bytes | ||
Smallest memory usage is @jridgewell/sourcemap-codec | ||
Encode speed: | ||
encode: @jridgewell/sourcemap-codec x 19,876 ops/sec ±0.78% (95 runs sampled) | ||
encode: sourcemap-codec x 6,983 ops/sec ±0.15% (100 runs sampled) | ||
encode: source-map-0.6.1 x 5,070 ops/sec ±0.12% (102 runs sampled) | ||
encode: source-map-0.8.0 x 5,641 ops/sec ±0.17% (100 runs sampled) | ||
Fastest is encode: @jridgewell/sourcemap-codec | ||
*** | ||
react.js.map - 5726 segments | ||
Decode Memory Usage: | ||
@jridgewell/sourcemap-codec 734848 bytes | ||
sourcemap-codec 954200 bytes | ||
source-map-0.6.1 2276432 bytes | ||
source-map-0.8.0 955488 bytes | ||
Smallest memory usage is @jridgewell/sourcemap-codec | ||
Decode speed: | ||
decode: @jridgewell/sourcemap-codec x 5,723 ops/sec ±0.12% (98 runs sampled) | ||
decode: sourcemap-codec x 4,555 ops/sec ±0.09% (101 runs sampled) | ||
decode: source-map-0.6.1 x 437 ops/sec ±0.11% (93 runs sampled) | ||
decode: source-map-0.8.0 x 3,441 ops/sec ±0.15% (100 runs sampled) | ||
Fastest is decode: @jridgewell/sourcemap-codec | ||
Encode Memory Usage: | ||
@jridgewell/sourcemap-codec 638672 bytes | ||
sourcemap-codec 1109840 bytes | ||
source-map-0.6.1 1321224 bytes | ||
source-map-0.8.0 1324448 bytes | ||
Smallest memory usage is @jridgewell/sourcemap-codec | ||
Encode speed: | ||
encode: @jridgewell/sourcemap-codec x 6,801 ops/sec ±0.48% (98 runs sampled) | ||
encode: sourcemap-codec x 2,533 ops/sec ±0.13% (101 runs sampled) | ||
encode: source-map-0.6.1 x 2,248 ops/sec ±0.08% (100 runs sampled) | ||
encode: source-map-0.8.0 x 2,303 ops/sec ±0.15% (100 runs sampled) | ||
Fastest is encode: @jridgewell/sourcemap-codec | ||
``` | ||
# License | ||
MIT |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34686
342
201