mirror of git://sourceware.org/git/glibc.git
(fnmatch): For short patterns or strings attempt to avoid calling mbsrtowcs twice.
This commit is contained in:
parent
9640622776
commit
7a409a1a7c
|
@ -327,11 +327,32 @@ fnmatch (pattern, string, flags)
|
||||||
{
|
{
|
||||||
mbstate_t ps;
|
mbstate_t ps;
|
||||||
size_t n;
|
size_t n;
|
||||||
|
const char *p;
|
||||||
wchar_t *wpattern;
|
wchar_t *wpattern;
|
||||||
wchar_t *wstring;
|
wchar_t *wstring;
|
||||||
|
|
||||||
/* Convert the strings into wide characters. */
|
/* Convert the strings into wide characters. */
|
||||||
memset (&ps, '\0', sizeof (ps));
|
memset (&ps, '\0', sizeof (ps));
|
||||||
|
p = pattern;
|
||||||
|
#ifdef _LIBC
|
||||||
|
n = strnlen (pattern, 1024);
|
||||||
|
#else
|
||||||
|
n = strlen (pattern);
|
||||||
|
#endif
|
||||||
|
if (__builtin_expect (n < 1024, 1))
|
||||||
|
{
|
||||||
|
wpattern = (wchar_t *) alloca ((n + 1) * sizeof (wchar_t));
|
||||||
|
n = mbsrtowcs (wpattern, &p, n + 1, &ps);
|
||||||
|
if (__builtin_expect (n == (size_t) -1, 0))
|
||||||
|
/* Something wrong.
|
||||||
|
XXX Do we have to set `errno' to something which mbsrtows hasn't
|
||||||
|
already done? */
|
||||||
|
return -1;
|
||||||
|
if (p)
|
||||||
|
memset (&ps, '\0', sizeof (ps));
|
||||||
|
}
|
||||||
|
if (__builtin_expect (p != NULL, 0))
|
||||||
|
{
|
||||||
n = mbsrtowcs (NULL, &pattern, 0, &ps);
|
n = mbsrtowcs (NULL, &pattern, 0, &ps);
|
||||||
if (__builtin_expect (n == (size_t) -1, 0))
|
if (__builtin_expect (n == (size_t) -1, 0))
|
||||||
/* Something wrong.
|
/* Something wrong.
|
||||||
|
@ -341,8 +362,29 @@ fnmatch (pattern, string, flags)
|
||||||
wpattern = (wchar_t *) alloca ((n + 1) * sizeof (wchar_t));
|
wpattern = (wchar_t *) alloca ((n + 1) * sizeof (wchar_t));
|
||||||
assert (mbsinit (&ps));
|
assert (mbsinit (&ps));
|
||||||
(void) mbsrtowcs (wpattern, &pattern, n + 1, &ps);
|
(void) mbsrtowcs (wpattern, &pattern, n + 1, &ps);
|
||||||
|
}
|
||||||
|
|
||||||
assert (mbsinit (&ps));
|
assert (mbsinit (&ps));
|
||||||
|
#ifdef _LIBC
|
||||||
|
n = strnlen (string, 1024);
|
||||||
|
#else
|
||||||
|
n = strlen (string);
|
||||||
|
#endif
|
||||||
|
p = string;
|
||||||
|
if (__builtin_expect (n < 1024, 1))
|
||||||
|
{
|
||||||
|
wstring = (wchar_t *) alloca ((n + 1) * sizeof (wchar_t));
|
||||||
|
n = mbsrtowcs (wstring, &p, n + 1, &ps);
|
||||||
|
if (__builtin_expect (n == (size_t) -1, 0))
|
||||||
|
/* Something wrong.
|
||||||
|
XXX Do we have to set `errno' to something which mbsrtows hasn't
|
||||||
|
already done? */
|
||||||
|
return -1;
|
||||||
|
if (p)
|
||||||
|
memset (&ps, '\0', sizeof (ps));
|
||||||
|
}
|
||||||
|
if (__builtin_expect (p != NULL, 0))
|
||||||
|
{
|
||||||
n = mbsrtowcs (NULL, &string, 0, &ps);
|
n = mbsrtowcs (NULL, &string, 0, &ps);
|
||||||
if (__builtin_expect (n == (size_t) -1, 0))
|
if (__builtin_expect (n == (size_t) -1, 0))
|
||||||
/* Something wrong.
|
/* Something wrong.
|
||||||
|
@ -352,6 +394,7 @@ fnmatch (pattern, string, flags)
|
||||||
wstring = (wchar_t *) alloca ((n + 1) * sizeof (wchar_t));
|
wstring = (wchar_t *) alloca ((n + 1) * sizeof (wchar_t));
|
||||||
assert (mbsinit (&ps));
|
assert (mbsinit (&ps));
|
||||||
(void) mbsrtowcs (wstring, &string, n + 1, &ps);
|
(void) mbsrtowcs (wstring, &string, n + 1, &ps);
|
||||||
|
}
|
||||||
|
|
||||||
return internal_fnwmatch (wpattern, wstring, wstring + n,
|
return internal_fnwmatch (wpattern, wstring, wstring + n,
|
||||||
flags & FNM_PERIOD, flags);
|
flags & FNM_PERIOD, flags);
|
||||||
|
|
Loading…
Reference in New Issue