mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 13:23:09 +00:00
Save a memory allocation in append_formatv
This commit is contained in:
parent
ed37427f9e
commit
f5e62f28bc
1 changed files with 8 additions and 9 deletions
21
common.cpp
21
common.cpp
|
@ -410,7 +410,7 @@ wcstring format_string(const wchar_t *format, ...)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
wcstring vformat_string(const wchar_t *format, va_list va_orig)
|
void append_formatv(wcstring &target, const wchar_t *format, va_list va_orig)
|
||||||
{
|
{
|
||||||
const int saved_err = errno;
|
const int saved_err = errno;
|
||||||
/*
|
/*
|
||||||
|
@ -461,22 +461,21 @@ wcstring vformat_string(const wchar_t *format, va_list va_orig)
|
||||||
va_end(va);
|
va_end(va);
|
||||||
}
|
}
|
||||||
|
|
||||||
wcstring result = wcstring(buff);
|
target.append(buff);
|
||||||
|
|
||||||
if (buff != static_buff)
|
if (buff != static_buff)
|
||||||
|
{
|
||||||
free(buff);
|
free(buff);
|
||||||
|
|
||||||
errno = saved_err;
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void append_formatv(wcstring &str, const wchar_t *format, va_list ap)
|
errno = saved_err;
|
||||||
{
|
}
|
||||||
/* Preserve errno across this call since it likes to stomp on it */
|
|
||||||
int err = errno;
|
|
||||||
str.append(vformat_string(format, ap));
|
|
||||||
errno = err;
|
|
||||||
|
|
||||||
|
wcstring vformat_string(const wchar_t *format, va_list va_orig)
|
||||||
|
{
|
||||||
|
wcstring result;
|
||||||
|
append_formatv(result, format, va_orig);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void append_format(wcstring &str, const wchar_t *format, ...)
|
void append_format(wcstring &str, const wchar_t *format, ...)
|
||||||
|
|
Loading…
Reference in a new issue