mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-28 00:21:52 +03:00
Micro-optimize critical path of strstr, strcase and memmem.
This commit is contained in:
@ -1,3 +1,9 @@
|
|||||||
|
2012-08-21 Maxim Kuvyrkov <maxim@codesourcery.com>
|
||||||
|
|
||||||
|
* string/str-two-way.h (AVAILABLE1_USES_J): New macro, define default.
|
||||||
|
(two_way_short_needle): Use it.
|
||||||
|
* string/{strstr.c, strcasestr.c} (AVAILABLE1_USES_J): Define.
|
||||||
|
|
||||||
2012-08-21 Maxim Kuvyrkov <maxim@codesourcery.com>
|
2012-08-21 Maxim Kuvyrkov <maxim@codesourcery.com>
|
||||||
|
|
||||||
* string/str-two-way.h (two_way_short_needle): Use pointers instead of
|
* string/str-two-way.h (two_way_short_needle): Use pointers instead of
|
||||||
|
@ -84,6 +84,9 @@
|
|||||||
#ifndef RET0_IF_0
|
#ifndef RET0_IF_0
|
||||||
# define RET0_IF_0(a) /* nothing */
|
# define RET0_IF_0(a) /* nothing */
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef AVAILABLE1_USES_J
|
||||||
|
# define AVAILABLE1_USES_J (1)
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Perform a critical factorization of NEEDLE, of length NEEDLE_LEN.
|
/* Perform a critical factorization of NEEDLE, of length NEEDLE_LEN.
|
||||||
Return the index of the first byte in the right half, and set
|
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++)))
|
!= (haystack_char = CANON_ELEMENT (*phaystack++)))
|
||||||
{
|
{
|
||||||
RET0_IF_0 (haystack_char);
|
RET0_IF_0 (haystack_char);
|
||||||
|
#if AVAILABLE1_USES_J
|
||||||
++j;
|
++j;
|
||||||
|
#endif
|
||||||
continue;
|
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;
|
j = phaystack - &haystack[suffix] - 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Scan for matches in right half. */
|
/* Scan for matches in right half. */
|
||||||
i = suffix + 1;
|
i = suffix + 1;
|
||||||
@ -497,6 +505,7 @@ two_way_long_needle (const unsigned char *haystack, size_t haystack_len,
|
|||||||
#undef AVAILABLE
|
#undef AVAILABLE
|
||||||
#undef AVAILABLE1
|
#undef AVAILABLE1
|
||||||
#undef AVAILABLE2
|
#undef AVAILABLE2
|
||||||
|
#undef AVAILABLE1_USES_J
|
||||||
#undef CANON_ELEMENT
|
#undef CANON_ELEMENT
|
||||||
#undef CMP_FUNC
|
#undef CMP_FUNC
|
||||||
#undef RET0_IF_0
|
#undef RET0_IF_0
|
||||||
|
@ -46,6 +46,7 @@
|
|||||||
#define AVAILABLE1(h, h_l, j, n_l) (true)
|
#define AVAILABLE1(h, h_l, j, n_l) (true)
|
||||||
#define AVAILABLE2(h, h_l, j, n_l) AVAILABLE (h, h_l, j, n_l)
|
#define AVAILABLE2(h, h_l, j, n_l) AVAILABLE (h, h_l, j, n_l)
|
||||||
#define RET0_IF_0(a) if (!a) goto ret0
|
#define RET0_IF_0(a) if (!a) goto ret0
|
||||||
|
#define AVAILABLE1_USES_J (0)
|
||||||
#define CANON_ELEMENT(c) TOLOWER (c)
|
#define CANON_ELEMENT(c) TOLOWER (c)
|
||||||
#define CMP_FUNC(p1, p2, l) \
|
#define CMP_FUNC(p1, p2, l) \
|
||||||
__strncasecmp ((const char *) (p1), (const char *) (p2), l)
|
__strncasecmp ((const char *) (p1), (const char *) (p2), l)
|
||||||
|
@ -38,6 +38,7 @@
|
|||||||
#define AVAILABLE1(h, h_l, j, n_l) (true)
|
#define AVAILABLE1(h, h_l, j, n_l) (true)
|
||||||
#define AVAILABLE2(h, h_l, j, n_l) AVAILABLE (h, h_l, j, n_l)
|
#define AVAILABLE2(h, h_l, j, n_l) AVAILABLE (h, h_l, j, n_l)
|
||||||
#define RET0_IF_0(a) if (!a) goto ret0
|
#define RET0_IF_0(a) if (!a) goto ret0
|
||||||
|
#define AVAILABLE1_USES_J (0)
|
||||||
#include "str-two-way.h"
|
#include "str-two-way.h"
|
||||||
|
|
||||||
#undef strstr
|
#undef strstr
|
||||||
|
Reference in New Issue
Block a user