Fixed `compressInt` cache bug (#1210)

Now `compressInt` uses the cache properly.
pull/1213/head
Jesús Lapastora 3 years ago committed by GitHub
parent 4608f33c03
commit d74d58afb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -13,15 +13,20 @@ function compressInt(i) {
// Zero value breaks
i += 1;
if (compressionCache[i]) {
return compressionCache[i];
// save `i` as the cache key
// to avoid it being modified by the
// rest of the function.
const cache_key = i;
if (compressionCache[cache_key]) {
return compressionCache[cache_key];
}
let result = "";
do {
result += charmap[i % charmap.length];
i = Math.floor(i / charmap.length);
} while (i > 0);
return (compressionCache[i] = result);
return (compressionCache[cache_key] = result);
}
/**

Loading…
Cancel
Save