summaryrefslogtreecommitdiff
path: root/src/buffer_utils.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2015-01-22 13:39:29 +0000
committerMaxime Coste <frrrwww@gmail.com>2015-01-22 13:39:29 +0000
commitcb197f57ba77ae16ed90d0e470f79d3245e16a70 (patch)
tree680eba24571af275b81b84071b5805a3ca535797 /src/buffer_utils.cc
parent2516c16bb9b35db18661ab180a41b0e157addefb (diff)
Avoid temporary strings on buffer load/reload
Pass directly a Vector<ref_ptr<StringStorage>> to the buffer
Diffstat (limited to 'src/buffer_utils.cc')
-rw-r--r--src/buffer_utils.cc16
1 files changed, 3 insertions, 13 deletions
diff --git a/src/buffer_utils.cc b/src/buffer_utils.cc
index b3b3e936..0b5941b9 100644
--- a/src/buffer_utils.cc
+++ b/src/buffer_utils.cc
@@ -39,24 +39,14 @@ Buffer* create_buffer_from_data(StringView data, StringView name,
pos = data.begin() + 3;
}
- Vector<String> lines;
+ BufferLines lines;
while (pos < data.end())
{
const char* line_end = pos;
while (line_end < data.end() and *line_end != '\r' and *line_end != '\n')
++line_end;
- // this should happen only when opening a file which has no
- // end of line as last character.
- if (line_end == data.end())
- {
- lines.emplace_back(pos, line_end);
- lines.back() += '\n';
- break;
- }
-
- lines.emplace_back(pos, line_end + 1);
- lines.back().back() = '\n';
+ lines.emplace_back(StringStorage::create({pos, line_end}, '\n'));
if (line_end+1 != data.end() and *line_end == '\r' and *(line_end+1) == '\n')
{
@@ -88,7 +78,7 @@ Buffer* create_fifo_buffer(String name, int fd, bool scroll)
if (buffer)
{
buffer->flags() |= Buffer::Flags::NoUndo;
- buffer->reload(Vector<String>({"\n"_str}), 0);
+ buffer->reload({"\n"_ss}, 0);
}
else
buffer = new Buffer(std::move(name), Buffer::Flags::Fifo | Buffer::Flags::NoUndo);