Skip to content

Commit

Permalink
Optimized string parsing to avoid unnecessary allocations.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ananya2 committed Feb 21, 2025
1 parent 81a19ed commit 3d07480
Showing 1 changed file with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ private static String[] escapeQuotesRFC4180(String[] tokens) throws SQLServerExc

private static String[] parseString(String buffer, String delimiter) {
ArrayList<String> tokens = new ArrayList<>();
StringBuilder currentToken = new StringBuilder();
int position = 0;
boolean quoted = false;
int braceCount = 0; // track nested JSON

Expand All @@ -668,17 +668,15 @@ private static String[] parseString(String buffer, String delimiter) {

// If delimiter is encountered and we're not inside quotes or JSON, we add the token
if (!quoted && braceCount == 0 && buffer.startsWith(delimiter, i)) {
tokens.add(currentToken.toString());
currentToken.setLength(0); // Reset current token
i += delimiter.length() - 1; // Skip delimiter
continue;
// Add field to token list when delimiter is found
tokens.add(buffer.substring(position, i));
position = i + delimiter.length();
i = position - 1;// Adjust the index to start after the delimiter
}

currentToken.append(c);
}

// Add the last field
tokens.add(currentToken.toString());
tokens.add(buffer.substring(position));
return tokens.toArray(new String[0]);
}
}

0 comments on commit 3d07480

Please sign in to comment.