From cb407be11b08c1c427fcf33a49974155e522e14a Mon Sep 17 00:00:00 2001 From: Josh Ferrell Date: Wed, 8 May 2024 16:19:26 -0400 Subject: Ref count undo objects --- database.cpp | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) (limited to 'database.cpp') diff --git a/database.cpp b/database.cpp index 26802f29..f3a6072f 100644 --- a/database.cpp +++ b/database.cpp @@ -298,41 +298,31 @@ DataBuffer Snapshot::GetUndoData() } -vector Snapshot::GetUndoEntries() +vector> Snapshot::GetUndoEntries() { return GetUndoEntries([](size_t, size_t) { return true; }); } -vector Snapshot::GetUndoEntries(const std::function& progress) +vector> Snapshot::GetUndoEntries(const std::function& progress) { ProgressContext pctxt; pctxt.callback = progress; - size_t numEntries; - BNUndoEntry* entries = BNGetSnapshotUndoEntriesWithProgress(m_object, &pctxt, ProgressCallback, &numEntries); + size_t count; + BNUndoEntry** entries = BNGetSnapshotUndoEntriesWithProgress(m_object, &pctxt, ProgressCallback, &count); if (entries == nullptr) { - throw DatabaseException("BNGetSnapshotUndoEntries"); + throw DatabaseException("BNGetSnapshotUndoEntriesWithProgress"); } - vector result; - result.reserve(numEntries); - for (size_t i = 0; i < numEntries; i++) + vector> result; + for (size_t i = 0; i < count; i++) { - UndoEntry temp; - temp.timestamp = entries[i].timestamp; - temp.id = entries[i].id; - temp.user = new User(BNNewUserReference(entries[i].user)); - size_t actionCount = entries[i].actionCount; - for (size_t actionIndex = 0; actionIndex < actionCount; actionIndex++) - { - temp.actions.emplace_back(entries[i].actions[actionIndex]); - } - result.push_back(temp); + result.push_back(new UndoEntry(BNNewUndoEntryReference(entries[i]))); } + BNFreeUndoEntryList(entries, count); - BNFreeUndoEntries(entries, numEntries); return result; } -- cgit v1.3.1