diff options
| author | Maxime Coste <mawww@kakoune.org> | 2017-01-30 12:05:04 +0000 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2017-01-30 13:38:38 +0000 |
| commit | f30e1642327b8ef4ceb967236192a833ace8e078 (patch) | |
| tree | 2033efcc9833a58dfc28dcd4724f38071513cb7c /src/shared_string.hh | |
| parent | 9d09d14d997e2d0dbca6bce5e4fe9ab2c3d25a85 (diff) | |
Make SharedString::create take a list of StringViews
Diffstat (limited to 'src/shared_string.hh')
| -rw-r--r-- | src/shared_string.hh | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/shared_string.hh b/src/shared_string.hh index a6522edb..ffd8bf04 100644 --- a/src/shared_string.hh +++ b/src/shared_string.hh @@ -6,6 +6,8 @@ #include "utils.hh" #include "unordered_map.hh" +#include <numeric> + namespace Kakoune { @@ -30,14 +32,19 @@ struct StringData : UseMemoryDomain<MemoryDomain::SharedString> static void ptr_moved(StringData*, void*, void*) noexcept {} }; - static RefPtr<StringData, PtrPolicy> create(StringView str, char back = 0) + static RefPtr<StringData, PtrPolicy> create(ArrayView<const StringView> strs) { - const int len = (int)str.length() + (back != 0 ? 1 : 0); + const int len = std::accumulate(strs.begin(), strs.end(), 0, + [](int l, StringView s) + { return l + (int)s.length(); }); void* ptr = StringData::operator new(sizeof(StringData) + len + 1); auto* res = new (ptr) StringData(0, len); - std::copy(str.begin(), str.end(), res->data()); - if (back != 0) - res->data()[len-1] = back; + auto* data = res->data(); + for (auto& str : strs) + { + memcpy(data, str.begin(), (size_t)str.length()); + data += (int)str.length(); + } res->data()[len] = 0; return RefPtr<StringData, PtrPolicy>{res}; } |
