perf(console): extend the filtered view incrementally
With any console filter on, each batch of new output rescanned all N lines to rebuild the visible set. A text filter lowercase-copied the needle and every line to test it: O(total characters) and 2N allocations per batch. When the filter is unchanged and the model only appended or evicted lines since the last pass, the visible indices drop the evicted lines and shift down, and only the new lines are tested. The result equals a full rescan, since line text and channel never change and the filtered view has no folds. A filter change, Clear, or a model window that doesn't follow on from the last one still rescans. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,10 @@
|
||||
|
||||
#include "console_channel.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace dragonx {
|
||||
namespace ui {
|
||||
@@ -20,5 +23,13 @@ bool consoleLinePassesFilter(const std::string& lineText,
|
||||
ConsoleChannel channel,
|
||||
const ConsoleOutputFilter& filter);
|
||||
|
||||
// Incrementally maintain a FLAT (filtered, fold-free) visible set across model appends/evictions. `visible` holds
|
||||
// ascending raw indices computed for the absolute window [oldFirst, oldEnd); the model now spans
|
||||
// [newFirst, newFirst + n). Drops evicted indices, rebases the survivors and appends every new raw index in
|
||||
// [oldEnd - newFirst, n) for which passes(i) is true. Returns false (visible untouched) when the windows do not
|
||||
// chain; the caller then rescans. Only valid while the filter is unchanged (line text/channel are immutable).
|
||||
bool ExtendFlatVisibleIndices(std::vector<int>& visible, std::uint64_t oldFirst, std::uint64_t oldEnd,
|
||||
std::uint64_t newFirst, int n, const std::function<bool(int)>& passes);
|
||||
|
||||
} // namespace ui
|
||||
} // namespace dragonx
|
||||
|
||||
Reference in New Issue
Block a user