Return int directly from CWeightTable::GetValueFromPixelWeight().
Currently, we return a potentially NULL pointer which needs to be
checked inside a very tight loop. This should never happen if we have
set up m_SrcStart and m_SrcEnd consistently with the number of weights
that we have allocated. We still keep the bounds checks in place for
safety, and return 0 in that case. Disassembly of StretchVert() in
an x64/Linux release build gets about 100 bytes shorter.
Change-Id: Ic187c3e514071550bd2c7bc0b4cbd43df2c4d13c
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/81930
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxge/dib/cstretchengine.cpp b/core/fxge/dib/cstretchengine.cpp
index ef39778..640efc9 100644
--- a/core/fxge/dib/cstretchengine.cpp
+++ b/core/fxge/dib/cstretchengine.cpp
@@ -148,13 +148,13 @@
&m_WeightTables[(pixel - m_DestMin) * m_ItemSizeBytes]);
}
-int* CStretchEngine::CWeightTable::GetValueFromPixelWeight(PixelWeight* pWeight,
- int index) const {
+int CStretchEngine::CWeightTable::GetValueFromPixelWeight(PixelWeight* pWeight,
+ int index) const {
if (index < pWeight->m_SrcStart)
- return nullptr;
+ return 0;
size_t idx = index - pWeight->m_SrcStart;
- return idx < GetPixelWeightCount() ? &pWeight->m_Weights[idx] : nullptr;
+ return idx < GetPixelWeightCount() ? pWeight->m_Weights[idx] : 0;
}
CStretchEngine::CStretchEngine(ScanlineComposerIface* pDestBitmap,
@@ -314,11 +314,8 @@
PixelWeight* pWeights = m_WeightTable.GetPixelWeight(col);
int dest_a = 0;
for (int j = pWeights->m_SrcStart; j <= pWeights->m_SrcEnd; ++j) {
- int* pWeight = m_WeightTable.GetValueFromPixelWeight(pWeights, j);
- if (!pWeight)
- return false;
-
- int pixel_weight = *pWeight;
+ int pixel_weight =
+ m_WeightTable.GetValueFromPixelWeight(pWeights, j);
if (src_scan[j / 8] & (1 << (7 - j % 8)))
dest_a += pixel_weight * 255;
}
@@ -331,11 +328,8 @@
PixelWeight* pWeights = m_WeightTable.GetPixelWeight(col);
int dest_a = 0;
for (int j = pWeights->m_SrcStart; j <= pWeights->m_SrcEnd; ++j) {
- int* pWeight = m_WeightTable.GetValueFromPixelWeight(pWeights, j);
- if (!pWeight)
- return false;
-
- int pixel_weight = *pWeight;
+ int pixel_weight =
+ m_WeightTable.GetValueFromPixelWeight(pWeights, j);
dest_a += pixel_weight * src_scan[j];
}
*dest_scan++ = static_cast<uint8_t>(dest_a >> kFixedPointBits);
@@ -348,11 +342,8 @@
int dest_a = 0;
int dest_r = 0;
for (int j = pWeights->m_SrcStart; j <= pWeights->m_SrcEnd; ++j) {
- int* pWeight = m_WeightTable.GetValueFromPixelWeight(pWeights, j);
- if (!pWeight)
- return false;
-
- int pixel_weight = *pWeight;
+ int pixel_weight =
+ m_WeightTable.GetValueFromPixelWeight(pWeights, j);
pixel_weight = pixel_weight * src_scan_mask[j] / 255;
dest_r += pixel_weight * src_scan[j];
dest_a += pixel_weight;
@@ -370,11 +361,8 @@
int dest_g = 0;
int dest_b = 0;
for (int j = pWeights->m_SrcStart; j <= pWeights->m_SrcEnd; ++j) {
- int* pWeight = m_WeightTable.GetValueFromPixelWeight(pWeights, j);
- if (!pWeight)
- return false;
-
- int pixel_weight = *pWeight;
+ int pixel_weight =
+ m_WeightTable.GetValueFromPixelWeight(pWeights, j);
unsigned long argb = m_pSrcPalette[src_scan[j]];
if (m_DestFormat == FXDIB_Format::kRgb) {
dest_r += pixel_weight * static_cast<uint8_t>(argb >> 16);
@@ -400,11 +388,8 @@
int dest_g = 0;
int dest_b = 0;
for (int j = pWeights->m_SrcStart; j <= pWeights->m_SrcEnd; ++j) {
- int* pWeight = m_WeightTable.GetValueFromPixelWeight(pWeights, j);
- if (!pWeight)
- return false;
-
- int pixel_weight = *pWeight;
+ int pixel_weight =
+ m_WeightTable.GetValueFromPixelWeight(pWeights, j);
pixel_weight = pixel_weight * src_scan_mask[j] / 255;
unsigned long argb = m_pSrcPalette[src_scan[j]];
dest_b += pixel_weight * static_cast<uint8_t>(argb >> 24);
@@ -427,11 +412,8 @@
int dest_g = 0;
int dest_b = 0;
for (int j = pWeights->m_SrcStart; j <= pWeights->m_SrcEnd; ++j) {
- int* pWeight = m_WeightTable.GetValueFromPixelWeight(pWeights, j);
- if (!pWeight)
- return false;
-
- int pixel_weight = *pWeight;
+ int pixel_weight =
+ m_WeightTable.GetValueFromPixelWeight(pWeights, j);
const uint8_t* src_pixel = src_scan + j * Bpp;
dest_b += pixel_weight * (*src_pixel++);
dest_g += pixel_weight * (*src_pixel++);
@@ -452,11 +434,8 @@
int dest_g = 0;
int dest_b = 0;
for (int j = pWeights->m_SrcStart; j <= pWeights->m_SrcEnd; ++j) {
- int* pWeight = m_WeightTable.GetValueFromPixelWeight(pWeights, j);
- if (!pWeight)
- return false;
-
- int pixel_weight = *pWeight;
+ int pixel_weight =
+ m_WeightTable.GetValueFromPixelWeight(pWeights, j);
const uint8_t* src_pixel = src_scan + j * Bpp;
if (m_DestFormat == FXDIB_Format::kArgb) {
pixel_weight = pixel_weight * src_pixel[3] / 255;
@@ -512,11 +491,7 @@
m_InterBuf.data() + (col - m_DestClip.left) * DestBpp;
int dest_a = 0;
for (int j = pWeights->m_SrcStart; j <= pWeights->m_SrcEnd; ++j) {
- int* pWeight = table.GetValueFromPixelWeight(pWeights, j);
- if (!pWeight)
- return;
-
- int pixel_weight = *pWeight;
+ int pixel_weight = table.GetValueFromPixelWeight(pWeights, j);
dest_a +=
pixel_weight * src_scan[(j - m_SrcClip.top) * m_InterPitch];
}
@@ -534,11 +509,7 @@
int dest_a = 0;
int dest_k = 0;
for (int j = pWeights->m_SrcStart; j <= pWeights->m_SrcEnd; ++j) {
- int* pWeight = table.GetValueFromPixelWeight(pWeights, j);
- if (!pWeight)
- return;
-
- int pixel_weight = *pWeight;
+ int pixel_weight = table.GetValueFromPixelWeight(pWeights, j);
dest_k +=
pixel_weight * src_scan[(j - m_SrcClip.top) * m_InterPitch];
dest_a += pixel_weight *
@@ -559,11 +530,7 @@
int dest_g = 0;
int dest_b = 0;
for (int j = pWeights->m_SrcStart; j <= pWeights->m_SrcEnd; ++j) {
- int* pWeight = table.GetValueFromPixelWeight(pWeights, j);
- if (!pWeight)
- return;
-
- int pixel_weight = *pWeight;
+ int pixel_weight = table.GetValueFromPixelWeight(pWeights, j);
const uint8_t* src_pixel =
src_scan + (j - m_SrcClip.top) * m_InterPitch;
dest_b += pixel_weight * (*src_pixel++);
@@ -590,11 +557,7 @@
int dest_g = 0;
int dest_b = 0;
for (int j = pWeights->m_SrcStart; j <= pWeights->m_SrcEnd; ++j) {
- int* pWeight = table.GetValueFromPixelWeight(pWeights, j);
- if (!pWeight)
- return;
-
- int pixel_weight = *pWeight;
+ int pixel_weight = table.GetValueFromPixelWeight(pWeights, j);
const uint8_t* src_pixel =
src_scan + (j - m_SrcClip.top) * m_InterPitch;
int mask_v = 255;
diff --git a/core/fxge/dib/cstretchengine.h b/core/fxge/dib/cstretchengine.h
index c61522e..d67e8bf 100644
--- a/core/fxge/dib/cstretchengine.h
+++ b/core/fxge/dib/cstretchengine.h
@@ -60,7 +60,7 @@
static_cast<const CWeightTable*>(this)->GetPixelWeight(pixel));
}
- int* GetValueFromPixelWeight(PixelWeight* pWeight, int index) const;
+ int GetValueFromPixelWeight(PixelWeight* pWeight, int index) const;
size_t GetPixelWeightCount() const;
private: