From ae9f4fa8761de5bc8b226fe896ab94f5f0b6d108 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sun, 26 Sep 2021 02:23:27 +0200 Subject: [PATCH] patterns: Increased highlighting performance --- .../hex/pattern_language/pattern_data.hpp | 17 +++++++++-------- source/views/view_pattern_editor.cpp | 6 +++--- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/plugins/libimhex/include/hex/pattern_language/pattern_data.hpp b/plugins/libimhex/include/hex/pattern_language/pattern_data.hpp index 88a6088ae..0ff8c5532 100644 --- a/plugins/libimhex/include/hex/pattern_language/pattern_data.hpp +++ b/plugins/libimhex/include/hex/pattern_language/pattern_data.hpp @@ -807,16 +807,17 @@ namespace hex::pl { std::optional highlightBytes(size_t offset) override{ auto entry = this->m_template->clone(); + ON_SCOPE_EXIT { delete entry; }; - for (u64 address = this->getOffset(); address < this->getOffset() + this->getSize(); address += this->m_template->getSize()) { - entry->setOffset(address); - if (auto color = entry->highlightBytes(offset); color.has_value()) - return color.value(); - } + if (offset < this->getOffset() || offset >= this->getOffset() + this->getSize()) + return { }; - delete entry; - - return { }; + auto index = (offset - this->getOffset()) / this->m_template->getSize(); + entry->setOffset(this->getOffset() + this->m_template->getSize() * index); + if (auto color = entry->highlightBytes(offset); color.has_value()) + return color.value(); + else + return { }; } std::map getHighlightedAddresses() override { diff --git a/source/views/view_pattern_editor.cpp b/source/views/view_pattern_editor.cpp index 83395cea9..dd43f0531 100644 --- a/source/views/view_pattern_editor.cpp +++ b/source/views/view_pattern_editor.cpp @@ -341,9 +341,9 @@ namespace hex { void ViewPatternEditor::parsePattern(char *buffer) { this->m_evaluatorRunning = true; - this->clearPatternData(); this->m_textEditor.SetErrorMarkers({ }); this->m_console.clear(); + this->clearPatternData(); EventManager::post(); std::thread([this, buffer = std::string(buffer)] { @@ -358,9 +358,9 @@ namespace hex { if (result.has_value()) { SharedData::patternData = std::move(result.value()); - View::doLater([]{ + //View::doLater([]{ EventManager::post(); - }); + //}); } this->m_evaluatorRunning = false;