Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Commit

Permalink
Merge pull request #276 from natergj/complex-string-lookup
Browse files Browse the repository at this point in the history
issue 269 fix. change Object lookup to Map
  • Loading branch information
natergj authored Mar 25, 2019
2 parents 1154b9e + 37a09c6 commit e0c40d4
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions source/lib/workbook/workbook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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];
Expand All @@ -258,10 +258,11 @@ class Workbook {
* @returns {Number} index of the string in the shared strings array
*/
getStringIndex(val) {
const target = this.sharedStringLookup[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[val] = index;
this.sharedStringLookup.set(lookupKey, index);
return index;
} else {
return target;
Expand Down

0 comments on commit e0c40d4

Please sign in to comment.