Skip to content

Commit

Permalink
fits: lazily create ColFitsStarTable per-column Inputs
Browse files Browse the repository at this point in the history
In ColFitsStarTable, create the per-column input objects only
when they are required, rather than pre-emptively for all columns,
in the RowSequence and RowAccess implementations.
Although this introduces an extra null test into each cell read
operation, this does not seem to impact the performance,
and it means that columns never needed are never (e.g.) mapped.
  • Loading branch information
mbtaylor committed Jan 10, 2021
1 parent e580eed commit b1990cf
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions fits/src/main/uk/ac/starlink/fits/ColFitsStarTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -764,15 +764,20 @@ private class ColFitsRowSequence implements RowSequence {
seqColReaders_ = new ColumnReader[ ncol_ ];
cursors_ = new long[ ncol_ ];
for ( int icol = 0; icol < ncol_; icol++ ) {
final BasicInput input =
inputFacts_[ icol ].createInput( true );
final InputFactory inputFact = inputFacts_[ icol ];
seqColReaders_[ icol ] =
new ColumnReader( valReaders_[ icol ] ) {
protected BasicInput getInput() {
return input;
BasicInput input_;
protected BasicInput getInput() throws IOException {
if ( input_ == null ) {
input_ = inputFact.createInput( true );
}
return input_;
}
public void close() throws IOException {
input.close();
if ( input_ != null ) {
input_.close();
}
}
};
cursors_[ icol ] = -1;
Expand Down Expand Up @@ -827,14 +832,19 @@ private class ColFitsRowAccess implements RowAccess {
ColFitsRowAccess() throws IOException {
colReaders_ = new ColumnReader[ ncol_ ];
for ( int icol = 0; icol < ncol_; icol++ ) {
final BasicInput input =
inputFacts_[ icol ].createInput( false );
final InputFactory inFact = inputFacts_[ icol ];
colReaders_[ icol ] = new ColumnReader( valReaders_[ icol ] ) {
protected BasicInput getInput() {
return input;
BasicInput input_;
protected BasicInput getInput() throws IOException {
if ( input_ == null ) {
input_ = inFact.createInput( false );
}
return input_;
}
public void close() throws IOException {
input.close();
if ( input_ != null ) {
input_.close();
}
}
};
}
Expand Down Expand Up @@ -938,7 +948,7 @@ private static abstract class ColumnReader implements Closeable {
*
* @return basic input
*/
protected abstract BasicInput getInput();
protected abstract BasicInput getInput() throws IOException;

/**
* Positions ready to read the value for a given row.
Expand Down

0 comments on commit b1990cf

Please sign in to comment.