Skip to content

Commit

Permalink
Very minor speed bump by using std::vector instead of QVector
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 2, 2020
1 parent 8e0c166 commit ecc0956
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/core/raster/qgscolorrampshader.cpp
Expand Up @@ -355,7 +355,7 @@ bool QgsColorRampShader::shade( double value, int *returnRedValue, int *returnGr
{
idx++;
}
mLUT.push_back( idx );
mLUT.emplace_back( idx );
}
}
}
Expand All @@ -372,7 +372,7 @@ bool QgsColorRampShader::shade( double value, int *returnRedValue, int *returnGr
{
idx = 0;
}
else if ( lutIndex >= mLUT.count() )
else if ( static_cast< std::size_t>( lutIndex ) >= mLUT.size() )
{
idx = colorRampItemListCount - 1;
if ( colorRampItems[idx].value + DOUBLE_DIFF_THRESHOLD < value )
Expand All @@ -387,7 +387,7 @@ bool QgsColorRampShader::shade( double value, int *returnRedValue, int *returnGr
else
{
// get initial value from LUT
idx = mLUT.at( lutIndex );
idx = mLUT[ lutIndex ];

// check if it's correct and if not increase until correct
// the LUT is made in such a way the index is always correct or too low, never too high
Expand Down Expand Up @@ -428,6 +428,7 @@ bool QgsColorRampShader::shade( double value, int *returnRedValue, int *returnGr
float currentRampRange = currentColorRampItem.value - previousColorRampItem.value;
float offsetInRange = value - previousColorRampItem.value;
float scale = offsetInRange / currentRampRange;

const QRgb c1 = previousColorRampItem.color.rgba();
const QRgb c2 = currentColorRampItem.color.rgba();

Expand Down
2 changes: 1 addition & 1 deletion src/core/raster/qgscolorrampshader.h
Expand Up @@ -222,7 +222,7 @@ class CORE_EXPORT QgsColorRampShader : public QgsRasterShaderFunction
* Look up table to speed up finding the right color.
* It is initialized on the first call to shade().
*/
mutable QVector<int> mLUT;
mutable std::vector<int> mLUT;
mutable double mLUTOffset = 0.0;
mutable double mLUTFactor = 1.0;
mutable bool mLUTInitialized = false;
Expand Down

0 comments on commit ecc0956

Please sign in to comment.