diff --git a/core/src/processing/data/Table.java b/core/src/processing/data/Table.java index 5272a2d66..a76ec9bfe 100644 --- a/core/src/processing/data/Table.java +++ b/core/src/processing/data/Table.java @@ -155,14 +155,30 @@ public class Table { public Table(Iterable rows) { init(); - boolean firstRow = true; - for (TableRow row : rows) { - if (firstRow) { - setColumnTypes(row.getColumnTypes()); - setColumnTitles(row.getColumnTitles()); - firstRow = false; + + int row = 0; + int alloc = 10; + + for (TableRow incoming : rows) { + if (row == 0) { + setColumnTypes(incoming.getColumnTypes()); + setColumnTitles(incoming.getColumnTitles()); + // Do this after setting types, otherwise it'll attempt to parse the + // allocated but empty rows, and drive CATEGORY columns nutso. + setRowCount(alloc); + + } else if (row == alloc) { + // Far more efficient than re-allocating all columns and doing a copy + alloc *= 2; + setRowCount(alloc); } - addRow(row); + + //addRow(row); + setRow(row++, incoming); + } + // Shrink the table to only the rows that were used + if (row != alloc) { + setRowCount(row); } } @@ -1837,7 +1853,11 @@ public class Table { * @param source a reference to the original row to be duplicated */ public TableRow addRow(TableRow source) { - int row = rowCount; + return setRow(rowCount, source); + } + + + public TableRow setRow(int row, TableRow source) { // Make sure there are enough columns to add this data ensureBounds(row, source.getColumnCount() - 1); diff --git a/core/todo.txt b/core/todo.txt index ad25fb3fd..3061686db 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -15,6 +15,7 @@ X add getColumnTitle(int) and getColumnTitles() to TableRow interface X fixes for new Table(Iterable) X category data types were not importing their dictionary X column titles weren't set on the new table +X drastic performance improvements for addRow() X when using setColumnType(), replace nulls with missingInt, missingFloat, etc X formerly, was throwing a NullPointerException