mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
Make contains
take the string by const reference again, for performance reasons
This commit is contained in:
parent
689d0082d8
commit
e47ad09130
2 changed files with 11 additions and 9 deletions
14
common.cpp
14
common.cpp
|
@ -576,7 +576,7 @@ wcstring wsetlocale(int category, const wchar_t *locale)
|
|||
return format_string(L"%s", res);
|
||||
}
|
||||
|
||||
bool contains_internal(const wchar_t *a, ...)
|
||||
bool contains_internal(const wchar_t *a, int vararg_handle, ...)
|
||||
{
|
||||
const wchar_t *arg;
|
||||
va_list va;
|
||||
|
@ -584,7 +584,7 @@ bool contains_internal(const wchar_t *a, ...)
|
|||
|
||||
CHECK(a, 0);
|
||||
|
||||
va_start(va, a);
|
||||
va_start(va, vararg_handle);
|
||||
while ((arg=va_arg(va, const wchar_t *))!= 0)
|
||||
{
|
||||
if (wcscmp(a,arg) == 0)
|
||||
|
@ -598,17 +598,19 @@ bool contains_internal(const wchar_t *a, ...)
|
|||
return res;
|
||||
}
|
||||
|
||||
/* wcstring variant of contains_internal. The first parameter is a wcstring, the rest are const wchar_t* */
|
||||
__sentinel bool contains_internal(const wcstring needle, ...)
|
||||
/* wcstring variant of contains_internal. The first parameter is a wcstring, the rest are const wchar_t *. vararg_handle exists only to give us a POD-value to apss to va_start */
|
||||
__sentinel bool contains_internal(const wcstring &needle, int vararg_handle, ...)
|
||||
{
|
||||
const wchar_t *arg;
|
||||
va_list va;
|
||||
int res = 0;
|
||||
|
||||
va_start(va, needle);
|
||||
const wchar_t *needle_cstr = needle.c_str();
|
||||
va_start(va, vararg_handle);
|
||||
while ((arg=va_arg(va, const wchar_t *))!= 0)
|
||||
{
|
||||
if (needle == arg)
|
||||
/* libc++ has an unfortunate implementation of operator== that unconditonally wcslen's the wchar_t* parameter, so prefer wcscmp directly */
|
||||
if (! wcscmp(needle_cstr, arg))
|
||||
{
|
||||
res=1;
|
||||
break;
|
||||
|
|
6
common.h
6
common.h
|
@ -228,7 +228,7 @@ extern const wchar_t *program_name;
|
|||
/**
|
||||
Check if the specified string element is a part of the specified string list
|
||||
*/
|
||||
#define contains( str,... ) contains_internal( str, __VA_ARGS__, NULL )
|
||||
#define contains( str, ... ) contains_internal( str, 0, __VA_ARGS__, NULL )
|
||||
|
||||
/**
|
||||
Print a stack trace to stderr
|
||||
|
@ -688,8 +688,8 @@ wcstring wsetlocale(int category, const wchar_t *locale);
|
|||
|
||||
\return zero if needle is not found, of if needle is null, non-zero otherwise
|
||||
*/
|
||||
__sentinel bool contains_internal(const wchar_t *needle, ...);
|
||||
__sentinel bool contains_internal(const wcstring needle, ...);
|
||||
__sentinel bool contains_internal(const wchar_t *needle, int vararg_handle, ...);
|
||||
__sentinel bool contains_internal(const wcstring &needle, int vararg_handle, ...);
|
||||
|
||||
/**
|
||||
Call read while blocking the SIGCHLD signal. Should only be called
|
||||
|
|
Loading…
Reference in a new issue