From 52b956f697ffee0a0faa54f4793c96e395a526f3 Mon Sep 17 00:00:00 2001 From: Nater Jorde Date: Sun, 24 Mar 2019 13:09:41 -0500 Subject: [PATCH 1/2] issue 269 fix. change Object lookup to Map --- source/lib/workbook/workbook.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/source/lib/workbook/workbook.js b/source/lib/workbook/workbook.js index e83d4d2..f124927 100644 --- a/source/lib/workbook/workbook.js +++ b/source/lib/workbook/workbook.js @@ -90,9 +90,9 @@ class Workbook { this.sheets = []; this.sharedStrings = []; - this.sharedStringLookup = {}; + this.sharedStringLookup = new Map(); this.styles = []; - this.stylesLookup = {}; + this.stylesLookup = new Map(); this.dxfCollection = new DXFCollection(this); this.mediaCollection = new MediaCollection(); this.definedNameCollection = new DefinedNameCollection(); @@ -242,11 +242,11 @@ class Workbook { const lookupKey = JSON.stringify(thisStyle.toObject()); // Use existing style if one exists - if (this.stylesLookup[lookupKey]) { - return this.stylesLookup[lookupKey]; + if (this.stylesLookup.get(lookupKey)) { + return this.stylesLookup.get(lookupKey); } - this.stylesLookup[lookupKey] = thisStyle; + this.stylesLookup.set(lookupKey, thisStyle); const index = this.styles.push(thisStyle) - 1; this.styles[index].ids.cellXfs = index; return this.styles[index]; @@ -258,10 +258,10 @@ class Workbook { * @returns {Number} index of the string in the shared strings array */ getStringIndex(val) { - const target = this.sharedStringLookup[val]; + const target = this.sharedStringLookup.get(val); if (_isUndefined(target)) { const index = this.sharedStrings.push(val) - 1; - this.sharedStringLookup[val] = index; + this.sharedStringLookup.set(val, index); return index; } else { return target; From 37a09c6012ad243366d25b7bf4a60a9b955dc9a4 Mon Sep 17 00:00:00 2001 From: Nater Jorde Date: Mon, 25 Mar 2019 16:18:57 -0500 Subject: [PATCH 2/2] use JSON.stringify for lookup keys of complex strings --- source/lib/workbook/workbook.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/lib/workbook/workbook.js b/source/lib/workbook/workbook.js index f124927..cc171e9 100644 --- a/source/lib/workbook/workbook.js +++ b/source/lib/workbook/workbook.js @@ -258,10 +258,11 @@ class Workbook { * @returns {Number} index of the string in the shared strings array */ getStringIndex(val) { - const target = this.sharedStringLookup.get(val); + const lookupKey = typeof val === "string" ? val : JSON.stringify(val); + const target = this.sharedStringLookup.get(lookupKey); if (_isUndefined(target)) { const index = this.sharedStrings.push(val) - 1; - this.sharedStringLookup.set(val, index); + this.sharedStringLookup.set(lookupKey, index); return index; } else { return target;