Skip to content

Commit

Permalink
optimize forEach operation by while-loop
Browse files Browse the repository at this point in the history
  • Loading branch information
justinpark committed May 3, 2023
1 parent da2810d commit 0d1cc15
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions superset-frontend/src/SqlLab/actions/sqlLab.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0d1cc15

Please sign in to comment.