Skip to content

Commit 1407334

Browse files
authored
Merge pull request dhorions#274 from dev-comrade/feat/addListToTable-performance
feat(data-table): fix poor performance addListToTable method
2 parents 5bf2885 + ad69d3e commit 1407334

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/main/java/be/quodlibet/boxable/datatable/DataTable.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -355,32 +355,31 @@ public Cell getLastColumnCellTemplateEven() {
355355
* @throws IOException parsing error
356356
*/
357357
public void addListToTable(List<List> data, Boolean hasHeader) throws IOException {
358-
char separator = ';';
359358
if (data == null || data.isEmpty()) {
360359
return;
361360
}
362-
String output = "";
361+
StringBuilder output = new StringBuilder();
362+
char separator = ';';
363+
363364
// Convert Map of arbitrary objects to a csv String
364365
for (List<? extends Object> inputList : data) {
366+
StringBuilder row = new StringBuilder();
365367
for (Object v : inputList) {
366368
String value = v.toString();
367369
if (value.contains("" + separator)) {
368370
// surround value with quotes if it contains the escape
369371
// character
370372
value = "\"" + value + "\"";
371-
}
373+
}
372374
value = value.replaceAll("\n", "<br>");
373-
output += value + separator;
375+
row.append(value).append(separator);
374376
}
375377
// remove the last separator
376-
output = removeLastChar(output);
377-
output += "\n";
378+
row = new StringBuilder(row.substring(0, row.length() - 1));
379+
output.append(row).append("\n");
378380
}
379-
addCsvToTable(output, hasHeader, separator);
380-
}
381381

382-
private static String removeLastChar(String str) {
383-
return str.substring(0, str.length() - 1);
382+
addCsvToTable(output.toString(), hasHeader, separator);
384383
}
385384

386385
/**

0 commit comments

Comments
 (0)