GraphicsMagick: coders/xpm.c (ReadXPMImage): Replace strcmp with...

GraphicsMagick Commits <[email protected]>
Newsgroups gmane.comp.video.graphicsmagick.cvs
Message-ID <mailman.10634.1667059917.1459.graphicsmagick-commit@lists.sourceforge.net>
changeset ea9b8002dc3d in /hg/GraphicsMagick
details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=ea9b8002dc3d
summary: coders/xpm.c (ReadXPMImage): Replace strcmp with faster memcmp. It improves 21% performance on my test image.

diffstat:

 ChangeLog    |   4 ++++
 coders/xpm.c |  19 ++++++++++++-------
 2 files changed, 16 insertions(+), 7 deletions(-)

diffs (48 lines):

diff -r d6f7fda3716b -r ea9b8002dc3d ChangeLog
--- a/ChangeLog	Fri Oct 28 17:59:05 2022 -0500
+++ b/ChangeLog	Sat Oct 29 10:33:21 2022 +0200
@@ -1,3 +1,7 @@
+2022-10-29  Fojtik Jaroslav  <[email protected]>
+	* coders/xpm.c (ReadXPMImage): Replace strcmp with faster memcmp.
+        It improves 21% performance on my test image.
+
 2022-10-28  Bob Friesenhahn  <[email protected]>
 
 	* coders/xpm.c (ReadXPMImage): Eliminate unnecessary strlen() upon
diff -r d6f7fda3716b -r ea9b8002dc3d coders/xpm.c
--- a/coders/xpm.c	Fri Oct 28 17:59:05 2022 -0500
+++ b/coders/xpm.c	Sat Oct 29 10:33:21 2022 +0200
@@ -502,7 +502,7 @@
         for (x=0; x < (long) image->columns; x++)
         {
           /* (void) strncpy(key,p,width); */
-          for (k=0; k < (long) width; k++)
+          for(k=0; k < (long) width; k++)
             {
               key[k]=p[k];
               if (p[k] == '\0')
@@ -511,13 +511,18 @@
                   break;
                 }
             }
-          if (MagickFail == status)
-            break;
-          key[k]='\0';
-          if (strcmp(key,keys[j]) != 0)
-            for (j=0; j < Max(image->colors-1,1); j++)
-              if (strcmp(key,keys[j]) == 0)
+          if(MagickFail == status)
+              break;
+          if(memcmp(key,keys[j],width) != 0)
+          {
+            j = Max(image->colors,1);
+            while(j-- > 0)	/* When j underflows, the VerifyColormapIndex stops reading. */
+            {
+              if(memcmp(key,keys[j],width) == 0)
                 break;
+            }
+          }
+
           VerifyColormapIndex(image,j);
           if (image->storage_class == PseudoClass)
             indexes[x]=(IndexPacket) j;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.