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

Commit

Permalink
Improves performance of checking for existing sharedStrings
Browse files Browse the repository at this point in the history
  • Loading branch information
刘馨 authored and natergj committed Jan 25, 2018
1 parent 352dd2f commit f2032ac
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions source/lib/workbook/workbook.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class Workbook {

this.sheets = [];
this.sharedStrings = [];
this.sharedStringLookup = {};
this.styles = [];
this.stylesLookup = {};
this.dxfCollection = new DXFCollection(this);
Expand Down Expand Up @@ -244,10 +245,14 @@ class Workbook {
* @returns {Number} index of the string in the shared strings array
*/
getStringIndex(val) {
if (this.sharedStrings.indexOf(val) < 0) {
this.sharedStrings.push(val);
const target = this.sharedStringLookup[val];
if (_.isUndefined(target)) {
const index = this.sharedStrings.push(val) - 1;
this.sharedStringLookup[val] = index;
return index;
} else {
return target;
}
return this.sharedStrings.indexOf(val);
}
}

Expand Down

0 comments on commit f2032ac

Please sign in to comment.