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
19 lines
738 B
C++
19 lines
738 B
C++
// RegexGuard.h - keep std::regex from overflowing the stack
|
|
//
|
|
// libstdc++'s std::regex matcher recurses roughly once per character of a
|
|
// match, so a pattern such as ".*" or "a+" on a line of a few tens of
|
|
// thousands of characters (minified JS/JSON) overflows a default 8 MiB
|
|
// stack and crashes the editor.
|
|
#pragma once
|
|
|
|
#include <functional>
|
|
|
|
namespace kte {
|
|
// Run fn to completion on a thread with a large stack (address space is
|
|
// reserved, pages are committed only as used), so regex work over long lines
|
|
// cannot overflow. If such a thread cannot be created, fn runs on the calling
|
|
// thread. Exceptions thrown by fn are rethrown to the caller.
|
|
void RunWithLargeStack(const std::function<void()> &fn);
|
|
|
|
} // namespace kte
|