From 73c6225906abde9c475bb22cdad4b2d3cd3371a2 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 21 Jul 2020 01:37:33 -0400 Subject: [PATCH] Correct space usage calculation for the clipboard in History dialog --- src/UndoManager.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/UndoManager.cpp b/src/UndoManager.cpp index 5582c23e7..2db73aebf 100644 --- a/src/UndoManager.cpp +++ b/src/UndoManager.cpp @@ -94,7 +94,7 @@ UndoManager::~UndoManager() namespace { SpaceArray::value_type - CalculateUsage(const TrackList &tracks, Set *seen) + CalculateUsage(const TrackList &tracks, Set &seen) { SpaceArray::value_type result = 0; @@ -110,17 +110,15 @@ namespace { { const auto &sb = block.sb; - // Accumulate space used by the file if the file was not + // Accumulate space used by the block if the block was not // yet seen - if ( !seen || (seen->count( sb->GetBlockID() ) == 0 ) ) + if ( seen.count( sb->GetBlockID() ) == 0 ) { unsigned long long usage{ sb->GetSpaceUsage() }; result += usage; - } - // Add file to current set - if (seen) - seen->insert( sb->GetBlockID() ); + seen.insert( sb->GetBlockID() ); + } } } } @@ -154,11 +152,14 @@ void UndoManager::CalculateSpaceUsage() { // Scan all tracks at current level auto &tracks = *stack[nn]->state.tracks; - space[nn] = CalculateUsage(tracks, &seen); + space[nn] = CalculateUsage(tracks, seen); } + // Count the usage of the clipboard separately, using another set. Do not + // multiple-count any block occurring multiple times within the clipboard. + Set seen2; mClipboardSpaceUsage = CalculateUsage( - Clipboard::Get().GetTracks(), nullptr); + Clipboard::Get().GetTracks(), seen2); //TIMER_STOP( space_calc ); }