mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-30 05:05:19 -05:00
patterns: Fixed [[static]] attribute and majorly reduced memory usage
Fixes #394
This commit is contained in:
@@ -30,8 +30,6 @@ namespace hex::plugin::builtin {
|
||||
private:
|
||||
MemoryEditor m_memoryEditor;
|
||||
|
||||
std::map<u64, u32> m_highlightedBytes;
|
||||
|
||||
std::vector<char> m_searchStringBuffer;
|
||||
std::vector<char> m_searchHexBuffer;
|
||||
SearchFunction m_searchFunction = nullptr;
|
||||
@@ -47,6 +45,7 @@ namespace hex::plugin::builtin {
|
||||
u64 m_resizeSize = 0;
|
||||
|
||||
std::vector<u8> m_dataToSave;
|
||||
std::set<pl::PatternData*> m_highlightedPatterns;
|
||||
|
||||
std::string m_loaderScriptScriptPath;
|
||||
std::string m_loaderScriptFilePath;
|
||||
|
||||
@@ -75,13 +75,24 @@ namespace hex::plugin::builtin {
|
||||
prevColor = (color & 0x00FFFFFF) | alpha;
|
||||
}
|
||||
|
||||
if (_this->m_highlightedBytes.contains(off)) {
|
||||
auto color = (_this->m_highlightedBytes[off] & 0x00FFFFFF) | alpha;
|
||||
currColor = currColor.has_value() ? ImAlphaBlendColors(color, currColor.value()) : color;
|
||||
}
|
||||
if (_this->m_highlightedBytes.contains(off - 1)) {
|
||||
auto color = (_this->m_highlightedBytes[off - 1] & 0x00FFFFFF) | alpha;
|
||||
prevColor = prevColor.has_value() ? ImAlphaBlendColors(color, prevColor.value()) : color;
|
||||
{
|
||||
for (const auto &pattern : SharedData::patternData) {
|
||||
auto child = pattern->getPattern(off);
|
||||
if (child != nullptr) {
|
||||
auto color = (child->getColor() & 0x00FFFFFF) | alpha;
|
||||
currColor = currColor.has_value() ? ImAlphaBlendColors(color, currColor.value()) : color;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto &pattern : SharedData::patternData) {
|
||||
auto child = pattern->getPattern(off - 1);
|
||||
if (child != nullptr) {
|
||||
auto color = (child->getColor() & 0x00FFFFFF) | alpha;
|
||||
prevColor = prevColor.has_value() ? ImAlphaBlendColors(color, currColor.value()) : color;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (next && prevColor != currColor) {
|
||||
@@ -151,7 +162,6 @@ namespace hex::plugin::builtin {
|
||||
EventManager::unsubscribe<RequestSelectionChange>(this);
|
||||
EventManager::unsubscribe<EventProjectFileLoad>(this);
|
||||
EventManager::unsubscribe<EventWindowClosing>(this);
|
||||
EventManager::unsubscribe<EventPatternChanged>(this);
|
||||
EventManager::unsubscribe<RequestOpenWindow>(this);
|
||||
EventManager::unsubscribe<EventSettingsChanged>(this);
|
||||
}
|
||||
@@ -642,7 +652,11 @@ namespace hex::plugin::builtin {
|
||||
|
||||
EventManager::post<EventFileLoaded>(path);
|
||||
EventManager::post<EventDataChanged>();
|
||||
EventManager::post<EventPatternChanged>();
|
||||
|
||||
{
|
||||
std::vector<pl::PatternData*> patterns;
|
||||
EventManager::post<EventPatternChanged>(patterns);
|
||||
}
|
||||
}
|
||||
|
||||
bool ViewHexEditor::saveToFile(const std::string &path, const std::vector<u8>& data) {
|
||||
@@ -1282,14 +1296,6 @@ R"(
|
||||
}
|
||||
});
|
||||
|
||||
EventManager::subscribe<EventPatternChanged>(this, [this]() {
|
||||
this->m_highlightedBytes.clear();
|
||||
|
||||
for (const auto &pattern : SharedData::patternData) {
|
||||
this->m_highlightedBytes.merge(pattern->getHighlightedAddresses());
|
||||
}
|
||||
});
|
||||
|
||||
EventManager::subscribe<RequestOpenWindow>(this, [this](std::string name) {
|
||||
if (name == "Create File") {
|
||||
hex::openFileBrowser("hex.builtin.view.hexeditor.create_file"_lang, DialogMode::Save, { }, [this](auto path) {
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace hex::plugin::builtin {
|
||||
|
||||
ViewPatternData::ViewPatternData() : View("hex.builtin.view.pattern_data.name") {
|
||||
|
||||
EventManager::subscribe<EventPatternChanged>(this, [this]() {
|
||||
EventManager::subscribe<EventPatternChanged>(this, [this](auto&) {
|
||||
this->m_sortedPatternData.clear();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -661,7 +661,11 @@ namespace hex::plugin::builtin {
|
||||
this->m_textEditor.SetErrorMarkers({ });
|
||||
this->m_console.clear();
|
||||
this->clearPatternData();
|
||||
EventManager::post<EventPatternChanged>();
|
||||
|
||||
{
|
||||
std::vector<pl::PatternData*> patterns;
|
||||
EventManager::post<EventPatternChanged>(patterns);
|
||||
}
|
||||
|
||||
std::thread([this, code] {
|
||||
std::map<std::string, pl::Token::Literal> envVars;
|
||||
@@ -691,7 +695,7 @@ namespace hex::plugin::builtin {
|
||||
|
||||
if (result.has_value()) {
|
||||
SharedData::patternData = std::move(result.value());
|
||||
EventManager::post<EventPatternChanged>();
|
||||
EventManager::post<EventPatternChanged>(SharedData::patternData);
|
||||
}
|
||||
|
||||
this->m_evaluatorRunning = false;
|
||||
|
||||
Reference in New Issue
Block a user