mirror of
https://github.com/tobspr/shapez.io.git
synced 2024-10-27 20:34:29 +00:00
Fixed compressInt
cache bug (#1210)
Now `compressInt` uses the cache properly.
This commit is contained in:
parent
4608f33c03
commit
d74d58afb7
@ -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…
Reference in New Issue
Block a user