View | Details | Raw Unified | Return to bug 47405
Collapse All | Expand All

(-)RowRecordsAggregate.java (-21 / +21 lines)
Lines 54-59 Link Here
54
	private final List<Record> _unknownRecords;
54
	private final List<Record> _unknownRecords;
55
	private final SharedValueManager _sharedValueManager;
55
	private final SharedValueManager _sharedValueManager;
56
56
57
	// Cache values to speed up serialization
58
	private RowRecord[] _rowRecordValues = null;
59
57
	/** Creates a new instance of ValueRecordsAggregate */
60
	/** Creates a new instance of ValueRecordsAggregate */
58
	public RowRecordsAggregate() {
61
	public RowRecordsAggregate() {
59
		this(SharedValueManager.createEmpty());
62
		this(SharedValueManager.createEmpty());
Lines 121-126 Link Here
121
	public void insertRow(RowRecord row) {
124
	public void insertRow(RowRecord row) {
122
		// Integer integer = Integer.valueOf(row.getRowNumber());
125
		// Integer integer = Integer.valueOf(row.getRowNumber());
123
		_rowRecords.put(Integer.valueOf(row.getRowNumber()), row);
126
		_rowRecords.put(Integer.valueOf(row.getRowNumber()), row);
127
		// Clear the cached values
128
		_rowRecordValues = null; 
124
		if ((row.getRowNumber() < _firstrow) || (_firstrow == -1)) {
129
		if ((row.getRowNumber() < _firstrow) || (_firstrow == -1)) {
125
			_firstrow = row.getRowNumber();
130
			_firstrow = row.getRowNumber();
126
		}
131
		}
Lines 141-146 Link Here
141
			_rowRecords.put(key, rr);
146
			_rowRecords.put(key, rr);
142
			throw new RuntimeException("Attempt to remove row that does not belong to this sheet");
147
			throw new RuntimeException("Attempt to remove row that does not belong to this sheet");
143
		}
148
		}
149
		
150
		// Clear the cached values
151
		_rowRecordValues = null;
144
	}
152
	}
145
153
146
	public RowRecord getRow(int rowIndex) {
154
	public RowRecord getRow(int rowIndex) {
Lines 193-214 Link Here
193
201
194
	/** Returns the physical row number of the first row in a block*/
202
	/** Returns the physical row number of the first row in a block*/
195
	private int getStartRowNumberForBlock(int block) {
203
	private int getStartRowNumberForBlock(int block) {
196
	  //Given that we basically iterate through the rows in order,
197
	  // TODO - For a performance improvement, it would be better to return an instance of
198
	  //an iterator and use that instance throughout, rather than recreating one and
199
	  //having to move it to the right position.
200
	  int startIndex = block * DBCellRecord.BLOCK_SIZE;
204
	  int startIndex = block * DBCellRecord.BLOCK_SIZE;
201
	  Iterator<RowRecord> rowIter = _rowRecords.values().iterator();
205
        if(_rowRecordValues == null)
202
	  RowRecord row = null;
206
            _rowRecordValues = _rowRecords.values().toArray(new RowRecord[0]);
203
	  //Position the iterator at the start of the block
207
204
	  for (int i=0; i<=startIndex;i++) {
208
        try {
205
		row = rowIter.next();
209
            return _rowRecordValues[startIndex].getRowNumber();
206
	  }
210
        } catch(ArrayIndexOutOfBoundsException e) {
207
	  if (row == null) {
208
		  throw new RuntimeException("Did not find start row for block " + block);
211
		  throw new RuntimeException("Did not find start row for block " + block);
209
	  }
212
	  }
210
211
	  return row.getRowNumber();
212
	}
213
	}
213
214
214
	/** Returns the physical row number of the end row in a block*/
215
	/** Returns the physical row number of the end row in a block*/
Lines 217-231 Link Here
217
	  if (endIndex >= _rowRecords.size())
218
	  if (endIndex >= _rowRecords.size())
218
		endIndex = _rowRecords.size()-1;
219
		endIndex = _rowRecords.size()-1;
219
220
220
	  Iterator<RowRecord> rowIter = _rowRecords.values().iterator();
221
        if(_rowRecordValues == null)
221
	  RowRecord row = null;
222
            _rowRecordValues = _rowRecords.values().toArray(new RowRecord[0]);
222
	  for (int i=0; i<=endIndex;i++) {
223
223
		row = rowIter.next();
224
        try {
224
	  }
225
            return _rowRecordValues[endIndex].getRowNumber();
225
	  if (row == null) {
226
        } catch(ArrayIndexOutOfBoundsException e) {
226
		  throw new RuntimeException("Did not find start row for block " + block);
227
            throw new RuntimeException("Did not find end row for block " + block);
227
	  }
228
	  }
228
	  return row.getRowNumber();
229
	}
229
	}
230
230
231
	private int visitRowRecordsForBlock(int blockIndex, RecordVisitor rv) {
231
	private int visitRowRecordsForBlock(int blockIndex, RecordVisitor rv) {

Return to bug 47405