This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch, fortran] optimize string comparison


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.

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;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]