Share search-match highlighting across renderers; engine owns its stack policy
SearchHighlight compiles the search pattern once per frame and yields each line's match ranges; the terminal, ImGui and Qt renderers had three copies of this, and Qt compiled a std::regex for every visible line on every frame. Qt now uses kte::Regex like the others. kte::Regex::RunGuarded replaces Command.cc's run_regex_work, which chose the large stack by comparing engine names. ForEachRegexMatch had no callers left and is removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015rcVQiiWyTzoNrsvLSaAfB
This commit is contained in:
@@ -49,21 +49,4 @@ RunWithLargeStack(const std::function<void()> &fn)
|
||||
std::rethrow_exception(job.error);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ForEachRegexMatch(const std::string &line, const std::regex &rx,
|
||||
const std::function<void(std::size_t, std::size_t)> &on_match)
|
||||
{
|
||||
auto scan = [&] {
|
||||
for (auto it = std::sregex_iterator(line.begin(), line.end(), rx); it != std::sregex_iterator(); ++it)
|
||||
on_match(static_cast<std::size_t>(it->position()), static_cast<std::size_t>(it->length()));
|
||||
};
|
||||
// Stack use grows with match length; a few hundred bytes stays far below
|
||||
// any thread's stack for every pattern we measured.
|
||||
constexpr std::size_t kInlineLimit = 512;
|
||||
if (line.size() <= kInlineLimit)
|
||||
scan();
|
||||
else
|
||||
RunWithLargeStack(scan);
|
||||
}
|
||||
} // namespace kte
|
||||
|
||||
Reference in New Issue
Block a user