aboutsummaryrefslogtreecommitdiffhomepage
path: root/common.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-04-30 16:29:52 -0700
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-04-30 16:29:52 -0700
commitf5e62f28bc7be454a173d3aedca136c7d514643a (patch)
treecf7242660dd48f015044e5a12f9cc9ce3ceb9aa2 /common.cpp
parented37427f9eb0a6dd436bfd087bcffdf869f96158 (diff)
Save a memory allocation in append_formatv
Diffstat (limited to 'common.cpp')
-rw-r--r--common.cpp17
1 files changed, 8 insertions, 9 deletions
diff --git a/common.cpp b/common.cpp
index 4bb15104..ac0181d3 100644
--- a/common.cpp
+++ b/common.cpp
@@ -410,7 +410,7 @@ wcstring format_string(const wchar_t *format, ...)
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;
/*
@@ -461,22 +461,21 @@ wcstring vformat_string(const wchar_t *format, va_list va_orig)
va_end(va);
}
- wcstring result = wcstring(buff);
+ target.append(buff);
if (buff != static_buff)
+ {
free(buff);
+ }
errno = saved_err;
- return result;
}
-void append_formatv(wcstring &str, const wchar_t *format, va_list ap)
+wcstring vformat_string(const wchar_t *format, va_list va_orig)
{
- /* Preserve errno across this call since it likes to stomp on it */
- int err = errno;
- str.append(vformat_string(format, ap));
- errno = err;
-
+ wcstring result;
+ append_formatv(result, format, va_orig);
+ return result;
}
void append_format(wcstring &str, const wchar_t *format, ...)