Skip to content

Commit 68fba22

Browse files
perf(css): spell each small source map delta once
1 parent 58849ee commit 68fba22

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

‎lib/util/SourceProcessor.js‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,28 @@ const _B64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
347347
* @returns {string} its Base64 VLQ encoding
348348
*/
349349
const _vlq = (n) => {
350+
// Most deltas are small, and each is spelled the same every time.
351+
if (n > -_VLQ_CACHED && n < _VLQ_CACHED) {
352+
if (_vlqCache === null) _vlqCache = Array.from({ length: _VLQ_CACHED * 2 });
353+
const cached = _vlqCache[n + _VLQ_CACHED];
354+
if (cached !== undefined) return cached;
355+
return (_vlqCache[n + _VLQ_CACHED] = _encodeVlq(n));
356+
}
357+
return _encodeVlq(n);
358+
};
359+
360+
// `_vlq` of every delta within this of zero, filled in as they are written,
361+
// and made only once a map is.
362+
const _VLQ_CACHED = 1024;
363+
/** @type {(string | undefined)[] | null} */
364+
let _vlqCache = null;
365+
366+
/**
367+
* One value as a Base64 VLQ, spelled out.
368+
* @param {number} n the value
369+
* @returns {string} its VLQ
370+
*/
371+
const _encodeVlq = (n) => {
350372
let v = n < 0 ? (-n << 1) | 1 : n << 1;
351373
let out = "";
352374
do {

0 commit comments

Comments
 (0)