From 0d1cc1550703605355654d39e3f055170d179de5 Mon Sep 17 00:00:00 2001 From: justin-park Date: Wed, 3 May 2023 09:27:48 -0700 Subject: [PATCH] optimize forEach operation by while-loop --- superset-frontend/src/SqlLab/actions/sqlLab.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/superset-frontend/src/SqlLab/actions/sqlLab.js b/superset-frontend/src/SqlLab/actions/sqlLab.js index f8bb9dd188174..d617fa23f5432 100644 --- a/superset-frontend/src/SqlLab/actions/sqlLab.js +++ b/superset-frontend/src/SqlLab/actions/sqlLab.js @@ -366,21 +366,28 @@ function splitByQuotedBlock(str) { let currentQuote = ''; let chunkStart = 0; - str.split('').forEach((currentChar, i) => { + let i = 0; + while (i < str.length) { + const currentChar = str[i]; if ( currentQuote ? currentChar === currentQuote : quotes.includes(currentChar) ) { + let chunk; if (currentQuote) { - chunks.push(str.substring(chunkStart, i + 1)); + chunk = str.substring(chunkStart, i + 1); chunkStart = i + 1; currentQuote = ''; } else { - chunks.push(str.substring(chunkStart, i)); + chunk = str.substring(chunkStart, i); chunkStart = i; currentQuote = currentChar; } + if (chunk) { + chunks.push(chunk); + } } - }); + i += 1; + } if (chunkStart < str.length) { const lastChunk = str.substring(chunkStart);