summaryrefslogtreecommitdiff
path: root/src/buffer.cc
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2024-02-28 19:00:51 +1100
committerMaxime Coste <mawww@kakoune.org>2024-02-28 19:02:29 +1100
commit3d5a0c672e6f3cf87944b33712e17531aa42c607 (patch)
treed402461b8d6517072b27e653d1201888366718a8 /src/buffer.cc
parent57b794ede3cae1e7c21309869a2c617481a55acf (diff)
Templatize StringData::create
This improves performance by letting the compiler optimize most use cases where string count and length are known are compile time.
Diffstat (limited to 'src/buffer.cc')
-rw-r--r--src/buffer.cc12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/buffer.cc b/src/buffer.cc
index 7054e6b8..9c38605a 100644
--- a/src/buffer.cc
+++ b/src/buffer.cc
@@ -430,14 +430,14 @@ BufferRange Buffer::do_insert(BufferCoord pos, StringView content)
if (content[i] == '\n')
{
StringView line = content.substr(start, i + 1 - start);
- new_lines.push_back(start == 0 ? StringData::create({prefix, line}) : StringData::create({line}));
+ new_lines.push_back(start == 0 ? StringData::create(prefix, line) : StringData::create(line));
start = i + 1;
}
}
if (start == 0)
- new_lines.push_back(StringData::create({prefix, content, suffix}));
+ new_lines.push_back(StringData::create(prefix, content, suffix));
else if (start != content.length() or not suffix.empty())
- new_lines.push_back(StringData::create({content.substr(start), suffix}));
+ new_lines.push_back(StringData::create(content.substr(start), suffix));
auto line_it = m_lines.begin() + (int)pos.line;
auto new_lines_it = new_lines.begin();
@@ -466,7 +466,7 @@ BufferCoord Buffer::do_erase(BufferCoord begin, BufferCoord end)
StringView prefix = m_lines[begin.line].substr(0, begin.column);
StringView suffix = end.line == line_count() ? StringView{} : m_lines[end.line].substr(end.column);
- auto new_line = (not prefix.empty() or not suffix.empty()) ? StringData::create({prefix, suffix}) : StringDataPtr{};
+ auto new_line = (not prefix.empty() or not suffix.empty()) ? StringData::create(prefix, suffix) : StringDataPtr{};
m_lines.erase(m_lines.begin() + (int)begin.line, m_lines.begin() + (int)end.line);
m_changes.push_back({ Change::Erase, begin, end });
@@ -691,7 +691,7 @@ String Buffer::debug_description() const
UnitTest test_buffer{[]()
{
- auto make_lines = [](auto&&... lines) { return BufferLines{StringData::create({lines})...}; };
+ auto make_lines = [](auto&&... lines) { return BufferLines{StringData::create(lines)...}; };
Buffer empty_buffer("empty", Buffer::Flags::None, make_lines("\n"));
@@ -738,7 +738,7 @@ UnitTest test_buffer{[]()
UnitTest test_undo{[]()
{
- auto make_lines = [](auto&&... lines) { return BufferLines{StringData::create({lines})...}; };
+ auto make_lines = [](auto&&... lines) { return BufferLines{StringData::create(lines)...}; };
Buffer buffer("test", Buffer::Flags::None, make_lines("allo ?\n", "mais que fais la police\n", " hein ?\n", " youpi\n"));
auto pos = buffer.end_coord();