From a176cdf74b94845d21f0e184b65a6cc134b3ef0f Mon Sep 17 00:00:00 2001 From: jjensenbloom <72892275+jjensenbloom@users.noreply.github.com> Date: Tue, 23 Jul 2024 11:48:07 -0700 Subject: [PATCH 1/2] Optimize createStyle When adding styles to a large number of cells, calling `new Style()` each time to check if the style exists is slow. Instead, the stringified style options are used as the lookup key before calling `new Style()`. --- source/lib/workbook/workbook.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source/lib/workbook/workbook.js b/source/lib/workbook/workbook.js index cc171e9c..76462afa 100644 --- a/source/lib/workbook/workbook.js +++ b/source/lib/workbook/workbook.js @@ -238,13 +238,14 @@ class Workbook { * @returns {Style} */ createStyle(opts) { - const thisStyle = new Style(this, opts); - const lookupKey = JSON.stringify(thisStyle.toObject()); + const lookupKey = JSON.stringify(opts); // Use existing style if one exists if (this.stylesLookup.get(lookupKey)) { return this.stylesLookup.get(lookupKey); } + + const thisStyle = new Style(this, opts); this.stylesLookup.set(lookupKey, thisStyle); const index = this.styles.push(thisStyle) - 1; @@ -279,4 +280,4 @@ class Workbook { } } -module.exports = Workbook; \ No newline at end of file +module.exports = Workbook; From bf07804821e9b4a4489413a85125c8c3000e72b6 Mon Sep 17 00:00:00 2001 From: jjensenbloom <72892275+jjensenbloom@users.noreply.github.com> Date: Tue, 23 Jul 2024 11:49:50 -0700 Subject: [PATCH 2/2] Remove blank line