Improve usage of CString

This cuts down 7 calls to free() to 1, when
instantiating a new program. There are still many low-hanging fruits
there.
This commit is contained in:
Mathias Agopian
2018-11-13 20:37:32 -08:00
committed by Mathias Agopian
parent 9bb87b8725
commit c1a7164084
6 changed files with 36 additions and 16 deletions

View File

@@ -18,6 +18,8 @@
#include <utils/compiler.h>
#include <memory>
namespace utils {
int StaticString::compare(const StaticString& rhs) const noexcept {
@@ -36,7 +38,8 @@ CString::CString(const char* cstr, size_type length) {
Data* p = (Data*)malloc(sizeof(Data) + length + 1);
p->length = length;
mCStr = (value_type*)(p + 1);
memcpy(mCStr, cstr, length + 1);
// we don't use memcpy here to avoid a call to libc, the generated code is pretty good.
std::uninitialized_copy_n(cstr, length + 1, mCStr);
}
}