Thursday, April 22, 2004

POI Optimization - Speeding up org.apache.poi.hssf.record.BlankRecord.compareTo()

This optimization is nearly identical to the one applied to HSSFRow.compareTo() - just used a local copy of the row and column values. This change reduced exceution time in my test case by 17.5 seconds.

    /**
     * switched to using a local copy of the row and column. Also moved the equality test to 
	 * the last test because it is most complex and probably least likely to be true.
     */
    public int compareTo(Object obj) {
        int rv = -1;
        CellValueRecordInterface loc = (CellValueRecordInterface) obj;

        int thisRow = this.getRow();
        int locRow = loc.getRow();

        if (thisRow < locRow) {
            rv = -1;
        } else if (thisRow > locRow) {
            rv = 1;
        } else {
            int thisColumn = this.getColumn();
            int locColumn = loc.getColumn();

            if (thisColumn > locColumn) {
                rv = 1;
            } else if (thisColumn < locColumn) {
                rv = -1;
            } else if ((thisRow == locRow) && (thisColumn == locColumn)) {
                rv = 0;
            }
        }
        return rv;
    }
Post a Comment