Skip to content

Commit 67f7af2

Browse files
committedDec 12, 2012
Some loop optimisations
1 parent 5c76a5f commit 67f7af2

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed
 

‎src/providers/gdal/qgsgdalprovider.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -395,16 +395,16 @@ void QgsGdalProvider::readBlock( int theBandNo, QgsRectangle const & theExtent,
395395

396396
int dataSize = dataTypeSize( theBandNo );
397397

398-
if( !mExtent.contains( theExtent ) )
398+
if ( !mExtent.contains( theExtent ) )
399399
{
400400
// fill with null values
401401
QByteArray ba = QgsRasterBlock::valueBytes( dataType( theBandNo ), noDataValue( theBandNo ) );
402402
char *nodata = ba.data();
403403
char *block = ( char * ) theBlock;
404404
for ( int i = 0; i < thePixelWidth * thePixelHeight; i++ )
405405
{
406-
memcpy( block, nodata, dataSize );
407-
block += dataSize;
406+
memcpy( block, nodata, dataSize );
407+
block += dataSize;
408408
}
409409
}
410410

@@ -564,23 +564,28 @@ void QgsGdalProvider::readBlock( int theBandNo, QgsRectangle const & theExtent,
564564
double tmpXRes = srcWidth * srcXRes / tmpWidth;
565565
double tmpYRes = srcHeight * srcYRes / tmpHeight; // negative
566566

567+
double y = myRasterExtent.yMaximum() - 0.5 * yRes;
567568
for ( int row = 0; row < height; row++ )
568569
{
569-
double y = myRasterExtent.yMaximum() - ( row + 0.5 ) * yRes;
570570
int tmpRow = static_cast<int>( floor( -1. * ( tmpYMax - y ) / tmpYRes ) );
571571

572572
char *srcRowBlock = tmpBlock + dataSize * tmpRow * tmpWidth;
573573
char *dstRowBlock = ( char * )theBlock + dataSize * ( top + row ) * thePixelWidth;
574-
for ( int col = 0; col < width; col++ )
574+
575+
double x = myRasterExtent.xMinimum() + 0.5 * xRes; // cell center
576+
char* dst = dstRowBlock + dataSize * left;
577+
char* src = 0;
578+
int tmpCol = 0;
579+
for ( int col = 0; col < width; ++col )
575580
{
576-
// cell center
577-
double x = myRasterExtent.xMinimum() + ( col + 0.5 ) * xRes;
578581
// floor() is quite slow! Use just cast to int.
579-
int tmpCol = static_cast<int>(( x - tmpXMin ) / tmpXRes ) ;
580-
char *src = srcRowBlock + dataSize * tmpCol;
581-
char *dst = dstRowBlock + dataSize * ( left + col );
582+
tmpCol = static_cast<int>(( x - tmpXMin ) / tmpXRes ) ;
583+
src = srcRowBlock + dataSize * tmpCol;
582584
memcpy( dst, src, dataSize );
585+
dst += dataSize;
586+
x += xRes;
583587
}
588+
y -= yRes;
584589
}
585590

586591
QgsFree( tmpBlock );

0 commit comments

Comments
 (0)
Please sign in to comment.