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:
@@ -32,5 +32,18 @@ bool consoleLinePassesFilter(const std::string& lineText,
|
||||
return true;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
const std::uint64_t newEnd = newFirst + static_cast<std::uint64_t>(n < 0 ? 0 : n);
|
||||
if (newFirst < oldFirst || newFirst > oldEnd || newEnd < oldEnd) return false;
|
||||
const int shift = static_cast<int>(newFirst - oldFirst);
|
||||
visible.erase(visible.begin(), std::lower_bound(visible.begin(), visible.end(), shift));
|
||||
for (int& idx : visible) idx -= shift;
|
||||
for (int i = static_cast<int>(oldEnd - newFirst); i < n; ++i)
|
||||
if (passes(i)) visible.push_back(i);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace ui
|
||||
} // namespace dragonx
|
||||
|
||||
Reference in New Issue
Block a user