Use key in obj syntax to decrease saving time to ~2%

This commit is contained in:
Tobias Berger 2021-10-02 21:50:30 +02:00
parent 228f8a47db
commit 7773009ab6

View file

@ -46,16 +46,16 @@ export class LZString extends StaticClass {
let value: number;
for (const contextC of uncompressed) {
if (!Object.keys(contextDictionary).includes(contextC)) {
if (!(contextC in contextDictionary)) {
contextDictionary[contextC] = contextDictSize++;
contextDictionaryToCreate[contextC] = true;
}
const contextWC = contextW + contextC;
if (Object.keys(contextDictionary).includes(contextWC)) {
if (contextWC in contextDictionary) {
contextW = contextWC;
} else {
if (Object.keys(contextDictionaryToCreate).includes(contextW)) {
if (contextW in contextDictionaryToCreate) {
if (contextW.charCodeAt(0) < 256) {
for (let i = 0; i < contextNumBits; i++) {
contextDataVal <<= 1;
@ -137,7 +137,7 @@ export class LZString extends StaticClass {
}
if (contextW !== "") {
if (Object.keys(contextDictionaryToCreate).includes(contextW)) {
if (contextW in contextDictionaryToCreate) {
if (contextW.charCodeAt(0) < 256) {
for (let i = 0; i < contextNumBits; i++) {
contextDataVal = contextDataVal << 1;