about summary refs log tree commit diff
path: root/string/str-two-way.h
diff options
context:
space:
mode:
authorMaxim Kuvyrkov <maxim@codesourcery.com>2012-05-28 22:46:07 -0700
committerMaxim Kuvyrkov <maxim@codesourcery.com>2012-08-21 18:07:47 -0700
commitbcca089526c6859e775243731037a469aec3065c (patch)
tree646370482233fa52fcb5311b066f65fef2946d84 /string/str-two-way.h
parent99677e575504ec526546501b1fdb86221493768a (diff)
downloadglibc-bcca089526c6859e775243731037a469aec3065c.tar.gz
glibc-bcca089526c6859e775243731037a469aec3065c.tar.xz
glibc-bcca089526c6859e775243731037a469aec3065c.zip
Micro-optimize critical path of strstr, strcase and memmem.
Diffstat (limited to 'string/str-two-way.h')
-rw-r--r--string/str-two-way.h11
1 files changed, 10 insertions, 1 deletions
diff --git a/string/str-two-way.h b/string/str-two-way.h
index 1b7a8baea0..59609b8685 100644
--- a/string/str-two-way.h
+++ b/string/str-two-way.h
@@ -84,6 +84,9 @@
 #ifndef RET0_IF_0
 # define RET0_IF_0(a) /* nothing */
 #endif
+#ifndef AVAILABLE1_USES_J
+# define AVAILABLE1_USES_J (1)
+#endif
 
 /* Perform a critical factorization of NEEDLE, of length NEEDLE_LEN.
    Return the index of the first byte in the right half, and set
@@ -295,12 +298,17 @@ two_way_short_needle (const unsigned char *haystack, size_t haystack_len,
 	      != (haystack_char = CANON_ELEMENT (*phaystack++)))
 	    {
 	      RET0_IF_0 (haystack_char);
+#if AVAILABLE1_USES_J
 	      ++j;
+#endif
 	      continue;
 	    }
 
-	  /* Calculate J.  */
+#if !AVAILABLE1_USES_J
+	  /* Calculate J if it wasn't kept up-to-date in the first-character
+	     loop.  */
 	  j = phaystack - &haystack[suffix] - 1;
+#endif
 
 	  /* Scan for matches in right half.  */
 	  i = suffix + 1;
@@ -497,6 +505,7 @@ two_way_long_needle (const unsigned char *haystack, size_t haystack_len,
 #undef AVAILABLE
 #undef AVAILABLE1
 #undef AVAILABLE2
+#undef AVAILABLE1_USES_J
 #undef CANON_ELEMENT
 #undef CMP_FUNC
 #undef RET0_IF_0