[poppler] poppler/GfxState.cc poppler/GfxState.h

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sun Dec 1 12:26:05 UTC 2019


 poppler/GfxState.cc |   33 +++++++++++----------------------
 poppler/GfxState.h  |    4 ++++
 2 files changed, 15 insertions(+), 22 deletions(-)

New commits:
commit 2a115270698e2f550536e7d69a1d022d5b67d89e
Author: Albert Astals Cid <aacid at kde.org>
Date:   Sun Dec 1 13:15:23 2019 +0100

    Move the clear for loops into a function
    
    And also call memset because it's clearer from "this is what i want"
    point of view, compiler optimizers are smart enough to convert back to a
    loop if needed

diff --git a/poppler/GfxState.cc b/poppler/GfxState.cc
index 92b764b2..a50bd2c9 100644
--- a/poppler/GfxState.cc
+++ b/poppler/GfxState.cc
@@ -728,8 +728,7 @@ void GfxDeviceGrayColorSpace::getCMYK(const GfxColor *color, GfxCMYK *cmyk) cons
 }
 
 void GfxDeviceGrayColorSpace::getDeviceN(const GfxColor *color, GfxColor *deviceN) const {
-  for (int i = 0; i < gfxColorMaxComps; i++)
-    deviceN->c[i] = 0;
+  clearGfxColor(deviceN);
   deviceN->c[3] = clip01(gfxColorComp1 - color->c[0]);
 }
 
@@ -934,8 +933,7 @@ void GfxCalGrayColorSpace::getCMYK(const GfxColor *color, GfxCMYK *cmyk) const {
 
 void GfxCalGrayColorSpace::getDeviceN(const GfxColor *color, GfxColor *deviceN) const {
   GfxCMYK cmyk;
-  for (int i = 0; i < gfxColorMaxComps; i++)
-    deviceN->c[i] = 0;
+  clearGfxColor(deviceN);
   getCMYK(color, &cmyk);
   deviceN->c[0] = cmyk.c;
   deviceN->c[1] = cmyk.m;
@@ -1076,8 +1074,7 @@ void GfxDeviceRGBColorSpace::getCMYK(const GfxColor *color, GfxCMYK *cmyk) const
 
 void GfxDeviceRGBColorSpace::getDeviceN(const GfxColor *color, GfxColor *deviceN) const {
   GfxCMYK cmyk;
-  for (int i = 0; i < gfxColorMaxComps; i++)
-    deviceN->c[i] = 0;
+  clearGfxColor(deviceN);
   getCMYK(color, &cmyk);
   deviceN->c[0] = cmyk.c;
   deviceN->c[1] = cmyk.m;
@@ -1301,8 +1298,7 @@ void GfxCalRGBColorSpace::getCMYK(const GfxColor *color, GfxCMYK *cmyk) const {
 
 void GfxCalRGBColorSpace::getDeviceN(const GfxColor *color, GfxColor *deviceN) const {
   GfxCMYK cmyk;
-  for (int i = 0; i < gfxColorMaxComps; i++)
-    deviceN->c[i] = 0;
+  clearGfxColor(deviceN);
   getCMYK(color, &cmyk);
   deviceN->c[0] = cmyk.c;
   deviceN->c[1] = cmyk.m;
@@ -1434,8 +1430,7 @@ void GfxDeviceCMYKColorSpace::getCMYK(const GfxColor *color, GfxCMYK *cmyk) cons
 }
 
 void GfxDeviceCMYKColorSpace::getDeviceN(const GfxColor *color, GfxColor *deviceN) const {
-  for (int i = 0; i < gfxColorMaxComps; i++)
-    deviceN->c[i] = 0;
+  clearGfxColor(deviceN);
   deviceN->c[0] = clip01(color->c[0]);
   deviceN->c[1] = clip01(color->c[1]);
   deviceN->c[2] = clip01(color->c[2]);
@@ -1689,8 +1684,7 @@ void GfxLabColorSpace::getCMYK(const GfxColor *color, GfxCMYK *cmyk) const {
 
 void GfxLabColorSpace::getDeviceN(const GfxColor *color, GfxColor *deviceN) const {
   GfxCMYK cmyk;
-  for (int i = 0; i < gfxColorMaxComps; i++)
-    deviceN->c[i] = 0;
+  clearGfxColor(deviceN);
   getCMYK(color, &cmyk);
   deviceN->c[0] = cmyk.c;
   deviceN->c[1] = cmyk.m;
@@ -2333,8 +2327,7 @@ bool GfxICCBasedColorSpace::useGetDeviceNLine() const {
 
 void GfxICCBasedColorSpace::getDeviceN(const GfxColor *color, GfxColor *deviceN) const {
   GfxCMYK cmyk;
-  for (int i = 0; i < gfxColorMaxComps; i++)
-    deviceN->c[i] = 0;
+  clearGfxColor(deviceN);
   getCMYK(color, &cmyk);
   deviceN->c[0] = cmyk.c;
   deviceN->c[1] = cmyk.m;
@@ -2783,8 +2776,7 @@ void GfxSeparationColorSpace::getCMYK(const GfxColor *color, GfxCMYK *cmyk) cons
 }
 
 void GfxSeparationColorSpace::getDeviceN(const GfxColor *color, GfxColor *deviceN) const {
-  for (int i = 0; i < gfxColorMaxComps; i++)
-    deviceN->c[i] = 0;
+  clearGfxColor(deviceN);
   if (mapping == nullptr || mapping[0] == -1) {
     GfxCMYK cmyk;
 
@@ -3062,8 +3054,7 @@ void GfxDeviceNColorSpace::getCMYK(const GfxColor *color, GfxCMYK *cmyk) const {
 }
 
 void GfxDeviceNColorSpace::getDeviceN(const GfxColor *color, GfxColor *deviceN) const {
-  for (int i = 0; i < gfxColorMaxComps; i++)
-    deviceN->c[i] = 0;
+  clearGfxColor(deviceN);
   if (mapping == nullptr) {
     GfxCMYK cmyk;
 
@@ -3230,8 +3221,7 @@ void GfxPatternColorSpace::getCMYK(const GfxColor *color, GfxCMYK *cmyk) const {
 }
 
 void GfxPatternColorSpace::getDeviceN(const GfxColor *color, GfxColor *deviceN) const {
-  for (int i = 0; i < gfxColorMaxComps; i++)
-    deviceN->c[i] = 0;
+  clearGfxColor(deviceN);
   deviceN->c[3] = 1;
 }
 
@@ -3813,8 +3803,7 @@ int GfxUnivariateShading::getColor(double t, GfxColor *color) {
   }
 
   if (unlikely(nFuncs < 1 || nComps > gfxColorMaxComps)) {
-    for (int i = 0; i < gfxColorMaxComps; i++)
-        color->c[i] = 0;
+    clearGfxColor(color);
     return gfxColorMaxComps;
   }
 
diff --git a/poppler/GfxState.h b/poppler/GfxState.h
index 8d2fbd3b..e57b8749 100644
--- a/poppler/GfxState.h
+++ b/poppler/GfxState.h
@@ -142,6 +142,10 @@ struct GfxColor {
   GfxColorComp c[gfxColorMaxComps];
 };
 
+static inline void clearGfxColor(GfxColor *gfxColor) {
+  memset(gfxColor->c, 0, sizeof(GfxColorComp) * gfxColorMaxComps);
+}
+
 //------------------------------------------------------------------------
 // GfxGray
 //------------------------------------------------------------------------


More information about the poppler mailing list