@@ -155,14 +155,30 @@ public Table(InputStream input, String options) throws IOException {
155155
156156 public Table (Iterable <TableRow > rows ) {
157157 init ();
158- boolean firstRow = true ;
159- for (TableRow row : rows ) {
160- if (firstRow ) {
161- setColumnTypes (row .getColumnTypes ());
162- setColumnTitles (row .getColumnTitles ());
163- firstRow = false ;
158+
159+ int row = 0 ;
160+ int alloc = 10 ;
161+
162+ for (TableRow incoming : rows ) {
163+ if (row == 0 ) {
164+ setColumnTypes (incoming .getColumnTypes ());
165+ setColumnTitles (incoming .getColumnTitles ());
166+ // Do this after setting types, otherwise it'll attempt to parse the
167+ // allocated but empty rows, and drive CATEGORY columns nutso.
168+ setRowCount (alloc );
169+
170+ } else if (row == alloc ) {
171+ // Far more efficient than re-allocating all columns and doing a copy
172+ alloc *= 2 ;
173+ setRowCount (alloc );
164174 }
165- addRow (row );
175+
176+ //addRow(row);
177+ setRow (row ++, incoming );
178+ }
179+ // Shrink the table to only the rows that were used
180+ if (row != alloc ) {
181+ setRowCount (row );
166182 }
167183 }
168184
@@ -1837,7 +1853,11 @@ public TableRow addRow() {
18371853 * @param source a reference to the original row to be duplicated
18381854 */
18391855 public TableRow addRow (TableRow source ) {
1840- int row = rowCount ;
1856+ return setRow (rowCount , source );
1857+ }
1858+
1859+
1860+ public TableRow setRow (int row , TableRow source ) {
18411861 // Make sure there are enough columns to add this data
18421862 ensureBounds (row , source .getColumnCount () - 1 );
18431863
0 commit comments