]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - string/memmem.c
Improve strstr performance
[thirdparty/glibc.git] / string / memmem.c
index 06704cbb7af5caca6df7f23fb107c78c5d247be1..43efaa3fb718e7a22c3b4122c278720768644d0f 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2012 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
 
 #ifndef _LIBC
 # define __builtin_expect(expr, val)   (expr)
+# define __memmem      memmem
 #endif
 
 #define RETURN_TYPE void *
 #define AVAILABLE(h, h_l, j, n_l) ((j) <= (h_l) - (n_l))
+#define FASTSEARCH(S,C,N) (void*) memchr ((void *)(S), (C), (N))
 #include "str-two-way.h"
 
 #undef memmem
@@ -38,8 +40,8 @@
    if NEEDLE_LEN is 0, otherwise NULL if NEEDLE is not found in
    HAYSTACK.  */
 void *
-memmem (const void *haystack_start, size_t haystack_len,
-       const void *needle_start, size_t needle_len)
+__memmem (const void *haystack_start, size_t haystack_len,
+         const void *needle_start, size_t needle_len)
 {
   /* Abstract memory is considered to be an array of 'unsigned char' values,
      not an array of 'char' values.  See ISO C 99 section 6.2.6.1.  */
@@ -53,7 +55,7 @@ memmem (const void *haystack_start, size_t haystack_len,
 
   /* Sanity check, otherwise the loop might search through the whole
      memory.  */
-  if (__builtin_expect (haystack_len < needle_len, 0))
+  if (__glibc_unlikely (haystack_len < needle_len))
     return NULL;
 
   /* Use optimizations in memchr when possible, to reduce the search
@@ -73,6 +75,8 @@ memmem (const void *haystack_start, size_t haystack_len,
   else
     return two_way_long_needle (haystack, haystack_len, needle, needle_len);
 }
-libc_hidden_def (memmem)
+libc_hidden_def (__memmem)
+weak_alias (__memmem, memmem)
+libc_hidden_weak (memmem)
 
 #undef LONG_NEEDLE_THRESHOLD