fix: Drastically improve pattern highlighting performance

This commit is contained in:
WerWolv 2022-07-01 19:05:53 +02:00
parent ef5fbba56b
commit 2d982e2088
3 changed files with 30 additions and 32 deletions

@ -1 +1 @@
Subproject commit f33fc83cedb1e74bd4f583c90ff77b397e7b5c03 Subproject commit 661ecab439922a923bb6ce1c01546044983d3bac

View File

@ -173,12 +173,12 @@ namespace hex::init {
auto meanScale = std::midpoint(xScale, yScale); auto meanScale = std::midpoint(xScale, yScale);
// On Macs with a retina display (basically all modern ones we care about), the OS reports twice // On Macs with a retina display (basically all modern ones we care about), the OS reports twice
// the actual monitor scale for some obscure reason. Get rid of this here so ImHex doesn't look // the actual monitor scale for some obscure reason. Get rid of this here so ImHex doesn't look
// extremely huge with native scaling on macOS. // extremely huge with native scaling on macOS.
#if defined(OS_MACOS) #if defined(OS_MACOS)
meanScale /= 2; meanScale /= 2;
#endif #endif
if (meanScale <= 0.0) { if (meanScale <= 0.0) {
meanScale = 1.0; meanScale = 1.0;

View File

@ -230,43 +230,39 @@ namespace hex::plugin::builtin {
}); });
ImHexApi::HexEditor::addBackgroundHighlightingProvider([](u64 address, const u8 *data, size_t size) -> std::optional<color_t> { ImHexApi::HexEditor::addBackgroundHighlightingProvider([this](u64 address, const u8 *data, size_t size) -> std::optional<color_t> {
hex::unused(data, size); hex::unused(data, size);
const auto &patterns = ImHexApi::Provider::get()->getPatternLanguageRuntime().getPatterns(); if (this->m_runningEvaluators != 0)
for (const auto &pattern : patterns) { return std::nullopt;
auto child = pattern->getPattern(address);
if (child != nullptr) {
return child->getColor();
}
}
return std::nullopt; const auto pattern = ImHexApi::Provider::get()->getPatternLanguageRuntime().getPattern(address, size);
if (pattern != nullptr)
return pattern->getColor();
else
return std::nullopt;
}); });
ImHexApi::HexEditor::addTooltipProvider([this](u64 address, const u8 *data, size_t size) { ImHexApi::HexEditor::addTooltipProvider([this](u64 address, const u8 *data, size_t size) {
hex::unused(data, size); hex::unused(data, size);
auto &patterns = ImHexApi::Provider::get()->getPatternLanguageRuntime().getPatterns(); auto pattern = ImHexApi::Provider::get()->getPatternLanguageRuntime().getPattern(address);
for (auto &pattern : patterns) { if (pattern != nullptr) {
auto child = pattern->getPattern(address); ImGui::BeginTooltip();
if (child != nullptr) {
ImGui::BeginTooltip();
if (ImGui::BeginTable("##tooltips", 1, ImGuiTableFlags_NoHostExtendX | ImGuiTableFlags_RowBg | ImGuiTableFlags_NoClip)) { if (ImGui::BeginTable("##tooltips", 1, ImGuiTableFlags_NoHostExtendX | ImGuiTableFlags_RowBg | ImGuiTableFlags_NoClip)) {
ImGui::TableNextRow(); ImGui::TableNextRow();
ImGui::TableNextColumn(); ImGui::TableNextColumn();
this->drawPatternTooltip(child); this->drawPatternTooltip(pattern);
auto tooltipColor = (child->getColor() & 0x00FF'FFFF) | 0x7000'0000; auto tooltipColor = (pattern->getColor() & 0x00FF'FFFF) | 0x7000'0000;
ImGui::PushStyleColor(ImGuiCol_TableRowBg, tooltipColor); ImGui::PushStyleColor(ImGuiCol_TableRowBg, tooltipColor);
ImGui::PushStyleColor(ImGuiCol_TableRowBgAlt, tooltipColor); ImGui::PushStyleColor(ImGuiCol_TableRowBgAlt, tooltipColor);
ImGui::EndTable(); ImGui::EndTable();
ImGui::PopStyleColor(2); ImGui::PopStyleColor(2);
}
ImGui::EndTooltip();
} }
ImGui::EndTooltip();
} }
}); });
} }
@ -787,6 +783,8 @@ namespace hex::plugin::builtin {
this->m_lastEvaluationError = runtime.getError(); this->m_lastEvaluationError = runtime.getError();
} }
runtime.flattenPatterns();
this->m_lastEvaluationLog = runtime.getConsoleLog(); this->m_lastEvaluationLog = runtime.getConsoleLog();
this->m_lastEvaluationOutVars = runtime.getOutVariables(); this->m_lastEvaluationOutVars = runtime.getOutVariables();
this->m_runningEvaluators--; this->m_runningEvaluators--;