fd/line: Memcpy is faster than insert
Change-Id: I22ce510db7066f6dce1fa59a3a8dbaa885d3ae8d
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/fd/line.cpp b/src/fd/line.cpp
index 36c1e6f..db12041 100644
--- a/src/fd/line.cpp
+++ b/src/fd/line.cpp
@@ -1,3 +1,4 @@
+#include <cstring>
#include <stdplus/exception.hpp>
#include <stdplus/fd/line.hpp>
#include <stdplus/fd/ops.hpp>
@@ -44,13 +45,17 @@
{
if (buf_data[i] == '\n')
{
- line.insert(line.end(), buf_data.begin(), buf_data.begin() + i);
+ auto oldsize = line.size();
+ line.resize(oldsize + i);
+ std::memcpy(line.data() + oldsize, buf_data.data(), i);
buf_data = buf_data.subspan(i + 1);
line_complete = true;
return &line;
}
}
- line.insert(line.end(), buf_data.begin(), buf_data.end());
+ auto oldsize = line.size();
+ line.resize(oldsize + buf_data.size());
+ std::memcpy(line.data() + oldsize, buf_data.data(), buf_data.size());
buf_data = {};
}
}