Patchwork [fortran] optimize string comparison

login
register
mail settings
Submitter Ondrej Bilka
Date March 27, 2013, 8:35 a.m.
Message ID <20130327083557.GB6374@domone.kolej.mff.cuni.cz>
Download mbox | patch
Permalink /patch/231608/
State New
Headers show

Comments

Ondrej Bilka - March 27, 2013, 8:35 a.m.
Hi, 
as I looked to compare_string I discovered that it could be
optimized. This speeds up case when strings are equal but we must check
padding where checking it byte by byte is suboptimal.

Ondra

2013-03-27  Ondřej Bílka  <neleai@seznam.cz>

	* libgfortran/intrinsics/string_intrinsics_inc.c (compare_string): Optimize.

Patch

diff --git a/libgfortran/intrinsics/string_intrinsics_inc.c b/libgfortran/intrinsics/string_intrinsics_inc.c
index a1f86b5..9eb0613 100644
--- a/libgfortran/intrinsics/string_intrinsics_inc.c
+++ b/libgfortran/intrinsics/string_intrinsics_inc.c
@@ -107,16 +107,15 @@  compare_string (gfc_charlen_type len1, const CHARTYPE *s1,
       res = 1;
     }
 
-  while (len--)
+	s = memchr (s, ' ', len);
+	if (!s)
+		return 0;
+  if (*s != ' ')
     {
-      if (*s != ' ')
-        {
-          if (*s > ' ')
-            return res;
-          else
-            return -res;
-        }
-      s++;
+      if (*s > ' ')
+        return res;
+      else
+        return -res;
     }
 
   return 0;