Load into the piece table's original store; save and copy without materializing
A loaded file's bytes are adopted as the piece table's original storage instead of being appended to the add buffer: the first keystroke no longer reallocates and copies the whole file (140 ms at 200 MB), and the read buffer is not copied again. Save writes the pieces in order instead of materializing the buffer (a second full copy that then stayed resident). Buffer::Bytes() assembles a copy from the pieces and replaces four hand-rolled copies (swap snapshots, recovery comparison, Command.cc's per-row join, the tests' accessor). A single-piece table (an unedited file) is viewed in place; GetLineView serves a line from its piece when it lies within one, so it no longer copies the whole buffer after every edit. Code that needed the whole text contiguous says so with ContentView(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015rcVQiiWyTzoNrsvLSaAfB
This commit is contained in:
@@ -18,19 +18,6 @@ constexpr int kMaxUArgCount = 1000000;
|
||||
|
||||
|
||||
namespace {
|
||||
static std::string
|
||||
buffer_bytes_via_views(const Buffer &b)
|
||||
{
|
||||
const std::size_t nrows = b.Nrows();
|
||||
std::string out;
|
||||
for (std::size_t i = 0; i < nrows; i++) {
|
||||
auto v = b.GetLineView(i);
|
||||
out.append(v.data(), v.size());
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
apply_pending_line(Editor &ed, const std::size_t line1)
|
||||
{
|
||||
@@ -597,11 +584,11 @@ Editor::process_pending_opens_()
|
||||
Buffer tmp;
|
||||
std::string oerr;
|
||||
if (tmp.OpenFromFile(req.path, oerr)) {
|
||||
const std::string orig = buffer_bytes_via_views(tmp);
|
||||
const std::string orig = tmp.Bytes();
|
||||
std::string rerr;
|
||||
std::uint64_t valid = 0;
|
||||
if (kte::SwapManager::ReplayFile(tmp, swp, rerr, &valid)) {
|
||||
std::string rec = buffer_bytes_via_views(tmp);
|
||||
std::string rec = tmp.Bytes();
|
||||
if (rec == orig) {
|
||||
// Nothing to recover. Remove the journal rather than
|
||||
// appending this session's records to it (it may end in a
|
||||
|
||||
Reference in New Issue
Block a user