Skip to content

Commit a713901

Browse files
committed
cache highlights
1 parent a79dec8 commit a713901

4 files changed

Lines changed: 27 additions & 4 deletions

File tree

include/entropy/hex_display_feature.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <cstdint>
4+
#include <map>
45
#include <string>
56
#include <vector>
67

@@ -28,6 +29,7 @@ class HexDisplayFeature {
2829
ImGui::PushID(getName().c_str());
2930
if (ImGui::ColorEdit4("Color", (float *)&col)) {
3031
color = ImGui::ColorConvertFloat4ToU32(col);
32+
highlightCache.clear();
3133
}
3234
ImGui::PopID();
3335
}
@@ -36,6 +38,7 @@ class HexDisplayFeature {
3638
unsigned int color_value = 0;
3739
if (sscanf(value.c_str(), "0x%X", &color_value) == 1) {
3840
color = color_value;
41+
highlightCache.clear();
3942
}
4043
}
4144
}
@@ -53,6 +56,7 @@ class HexDisplayFeature {
5356

5457
public:
5558
mutable uint32_t color = IM_COL32(255, 0, 0, 255); // Default red color
59+
mutable std::map<size_t, std::vector<Highlight>> highlightCache;
5660
};
5761

5862
} // namespace entropy

include/entropy/hexdisplay/aewf_detector.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
#include <entropy/hex_display_feature.h>
88

9-
#include <iostream>
10-
119
namespace entropy {
1210

1311
class AEWFDetector : public HexDisplayFeature {

include/entropy/hexdisplay/zero_bytes.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ class ZeroBytesFeature : public HexDisplayFeature {
3737
// Default Config (color)
3838
HexDisplayFeature::renderSettingsPanel();
3939

40-
ImGui::Checkbox("Color FF as well", &colorFF);
40+
bool changed = ImGui::Checkbox("Color FF as well", &colorFF);
41+
if (changed) {
42+
highlightCache.clear();
43+
}
4144

4245
ImGui::PopID();
4346
}
@@ -59,6 +62,7 @@ class ZeroBytesFeature : public HexDisplayFeature {
5962
void setConfig(const std::string &key, const std::string &value) override {
6063
if (key == "colorFF") {
6164
colorFF = (value == "1");
65+
highlightCache.clear();
6266
return;
6367
}
6468
// default options

src/ui.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,29 @@ void renderHexViewWindow(UiState &uiState, const AppState &appState) {
5858
if (uiState.currentSectorData.empty()) {
5959
ImGui::Text("No data available");
6060
} else {
61+
// Clear highlight cache if sector changed
62+
static size_t lastSectorIndex = SIZE_MAX;
63+
if (lastSectorIndex != uiState.currentSectorIndex) {
64+
if (appState.hexDisplayFeatureManager) {
65+
for (auto *feature : appState.hexDisplayFeatureManager->getFeatures()) {
66+
feature->highlightCache.clear();
67+
}
68+
}
69+
lastSectorIndex = uiState.currentSectorIndex;
70+
}
71+
6172
// Collect highlights from plugins
6273
std::map<size_t, std::pair<uint32_t, int>> highlightMap; // color, priority
6374
if (appState.hexDisplayFeatureManager) {
6475
for (const auto *feature : appState.hexDisplayFeatureManager->getFeatures()) {
6576
if (appState.featureEnabled.count(feature->getName()) && appState.featureEnabled.at(feature->getName())) {
66-
auto highlights = feature->getHighlights(uiState.currentSectorData, uiState.currentSectorIndex);
77+
std::vector<Highlight> highlights;
78+
if (feature->highlightCache.count(uiState.currentSectorIndex)) {
79+
highlights = feature->highlightCache[uiState.currentSectorIndex];
80+
} else {
81+
highlights = feature->getHighlights(uiState.currentSectorData, uiState.currentSectorIndex);
82+
feature->highlightCache[uiState.currentSectorIndex] = highlights;
83+
}
6784
int priority = feature->getPriority();
6885
for (const auto &h : highlights) {
6986
auto it = highlightMap.find(h.offset);

0 commit comments

Comments
 (0)