Use key in obj
syntax to decrease saving time to ~2%
This commit is contained in:
parent
228f8a47db
commit
7773009ab6
1 changed files with 4 additions and 4 deletions
|
@ -46,16 +46,16 @@ export class LZString extends StaticClass {
|
||||||
let value: number;
|
let value: number;
|
||||||
|
|
||||||
for (const contextC of uncompressed) {
|
for (const contextC of uncompressed) {
|
||||||
if (!Object.keys(contextDictionary).includes(contextC)) {
|
if (!(contextC in contextDictionary)) {
|
||||||
contextDictionary[contextC] = contextDictSize++;
|
contextDictionary[contextC] = contextDictSize++;
|
||||||
contextDictionaryToCreate[contextC] = true;
|
contextDictionaryToCreate[contextC] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const contextWC = contextW + contextC;
|
const contextWC = contextW + contextC;
|
||||||
if (Object.keys(contextDictionary).includes(contextWC)) {
|
if (contextWC in contextDictionary) {
|
||||||
contextW = contextWC;
|
contextW = contextWC;
|
||||||
} else {
|
} else {
|
||||||
if (Object.keys(contextDictionaryToCreate).includes(contextW)) {
|
if (contextW in contextDictionaryToCreate) {
|
||||||
if (contextW.charCodeAt(0) < 256) {
|
if (contextW.charCodeAt(0) < 256) {
|
||||||
for (let i = 0; i < contextNumBits; i++) {
|
for (let i = 0; i < contextNumBits; i++) {
|
||||||
contextDataVal <<= 1;
|
contextDataVal <<= 1;
|
||||||
|
@ -137,7 +137,7 @@ export class LZString extends StaticClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contextW !== "") {
|
if (contextW !== "") {
|
||||||
if (Object.keys(contextDictionaryToCreate).includes(contextW)) {
|
if (contextW in contextDictionaryToCreate) {
|
||||||
if (contextW.charCodeAt(0) < 256) {
|
if (contextW.charCodeAt(0) < 256) {
|
||||||
for (let i = 0; i < contextNumBits; i++) {
|
for (let i = 0; i < contextNumBits; i++) {
|
||||||
contextDataVal = contextDataVal << 1;
|
contextDataVal = contextDataVal << 1;
|
||||||
|
|
Reference in a new issue