impr: Make hex editor faster to render
This commit is contained in:
parent
7a81fa7ac5
commit
8a289d2e4f
@ -269,13 +269,13 @@ namespace hex::ui {
|
|||||||
|
|
||||||
if (m_editingAddress != address || m_editingCellType != cellType) {
|
if (m_editingAddress != address || m_editingCellType != cellType) {
|
||||||
if (cellType == CellType::Hex) {
|
if (cellType == CellType::Hex) {
|
||||||
std::vector<u8> buffer(size);
|
std::array<u8, 32> buffer;
|
||||||
std::memcpy(buffer.data(), data, size);
|
std::memcpy(buffer.data(), data, std::min(size, buffer.size()));
|
||||||
|
|
||||||
if (m_dataVisualizerEndianness != std::endian::native)
|
if (m_dataVisualizerEndianness != std::endian::native)
|
||||||
std::reverse(buffer.begin(), buffer.end());
|
std::reverse(buffer.begin(), buffer.begin() + size);
|
||||||
|
|
||||||
m_currDataVisualizer->draw(address, buffer.data(), buffer.size(), m_upperCaseHex);
|
m_currDataVisualizer->draw(address, buffer.data(), size, m_upperCaseHex);
|
||||||
} else {
|
} else {
|
||||||
asciiVisualizer.draw(address, data, size, m_upperCaseHex);
|
asciiVisualizer.draw(address, data, size, m_upperCaseHex);
|
||||||
}
|
}
|
||||||
@ -530,6 +530,8 @@ namespace hex::ui {
|
|||||||
m_visibleRowCount = std::max<i64>(m_visibleRowCount, 1);
|
m_visibleRowCount = std::max<i64>(m_visibleRowCount, 1);
|
||||||
|
|
||||||
// Loop over rows
|
// Loop over rows
|
||||||
|
std::vector<u8> bytes(m_bytesPerRow, 0x00);
|
||||||
|
std::vector<std::tuple<std::optional<color_t>, std::optional<color_t>>> cellColors(m_bytesPerRow / bytesPerCell);
|
||||||
for (ImS64 y = m_scrollPosition; y < (m_scrollPosition + m_visibleRowCount + 5) && y < numRows && numRows != 0; y++) {
|
for (ImS64 y = m_scrollPosition; y < (m_scrollPosition + m_visibleRowCount + 5) && y < numRows && numRows != 0; y++) {
|
||||||
// Draw address column
|
// Draw address column
|
||||||
ImGui::TableNextRow();
|
ImGui::TableNextRow();
|
||||||
@ -539,12 +541,10 @@ namespace hex::ui {
|
|||||||
|
|
||||||
const u8 validBytes = std::min<u64>(m_bytesPerRow, m_provider->getSize() - y * m_bytesPerRow);
|
const u8 validBytes = std::min<u64>(m_bytesPerRow, m_provider->getSize() - y * m_bytesPerRow);
|
||||||
|
|
||||||
std::vector<u8> bytes(m_bytesPerRow, 0x00);
|
|
||||||
m_provider->read(y * m_bytesPerRow + m_provider->getBaseAddress() + m_provider->getCurrentPageAddress(), bytes.data(), validBytes);
|
m_provider->read(y * m_bytesPerRow + m_provider->getBaseAddress() + m_provider->getCurrentPageAddress(), bytes.data(), validBytes);
|
||||||
|
|
||||||
std::vector<std::tuple<std::optional<color_t>, std::optional<color_t>>> cellColors;
|
|
||||||
{
|
{
|
||||||
for (u64 x = 0; x < std::ceil(float(validBytes) / bytesPerCell); x++) {
|
for (u64 x = 0; x < std::ceil(float(validBytes) / bytesPerCell); x++) {
|
||||||
const u64 byteAddress = y * m_bytesPerRow + x * bytesPerCell + m_provider->getBaseAddress() + m_provider->getCurrentPageAddress();
|
const u64 byteAddress = y * m_bytesPerRow + x * bytesPerCell + m_provider->getBaseAddress() + m_provider->getCurrentPageAddress();
|
||||||
|
|
||||||
const auto cellBytes = std::min<u64>(validBytes, bytesPerCell);
|
const auto cellBytes = std::min<u64>(validBytes, bytesPerCell);
|
||||||
@ -567,15 +567,15 @@ namespace hex::ui {
|
|||||||
foregroundColor = ImGui::GetColorU32(ImGuiCol_TextDisabled);
|
foregroundColor = ImGui::GetColorU32(ImGuiCol_TextDisabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
cellColors.emplace_back(
|
cellColors[x] = {
|
||||||
foregroundColor,
|
foregroundColor,
|
||||||
backgroundColor
|
backgroundColor
|
||||||
);
|
};
|
||||||
} else {
|
} else {
|
||||||
cellColors.emplace_back(
|
cellColors[x] = {
|
||||||
std::nullopt,
|
std::nullopt,
|
||||||
std::nullopt
|
std::nullopt
|
||||||
);
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -634,7 +634,7 @@ namespace hex::ui {
|
|||||||
if (isCurrRegionValid(byteAddress))
|
if (isCurrRegionValid(byteAddress))
|
||||||
this->drawCell(byteAddress, &bytes[x * bytesPerCell], bytesPerCell, cellHovered, CellType::Hex);
|
this->drawCell(byteAddress, &bytes[x * bytesPerCell], bytesPerCell, cellHovered, CellType::Hex);
|
||||||
else
|
else
|
||||||
ImGuiExt::TextFormatted("{}", std::string(maxCharsPerCell, '?'));
|
ImGuiExt::TextFormatted("{:?>{}}", "", maxCharsPerCell);
|
||||||
|
|
||||||
if (cellHovered) {
|
if (cellHovered) {
|
||||||
hoveredCell = { byteAddress, bytesPerCell };
|
hoveredCell = { byteAddress, bytesPerCell };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user