From 8a289d2e4f939e9282b46a19c0bdd7a070d173d2 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Fri, 31 May 2024 17:02:22 +0200 Subject: [PATCH] impr: Make hex editor faster to render --- plugins/ui/source/ui/hex_editor.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/plugins/ui/source/ui/hex_editor.cpp b/plugins/ui/source/ui/hex_editor.cpp index 97c248dfa..965343bb7 100644 --- a/plugins/ui/source/ui/hex_editor.cpp +++ b/plugins/ui/source/ui/hex_editor.cpp @@ -269,13 +269,13 @@ namespace hex::ui { if (m_editingAddress != address || m_editingCellType != cellType) { if (cellType == CellType::Hex) { - std::vector buffer(size); - std::memcpy(buffer.data(), data, size); + std::array buffer; + std::memcpy(buffer.data(), data, std::min(size, buffer.size())); 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 { asciiVisualizer.draw(address, data, size, m_upperCaseHex); } @@ -530,6 +530,8 @@ namespace hex::ui { m_visibleRowCount = std::max(m_visibleRowCount, 1); // Loop over rows + std::vector bytes(m_bytesPerRow, 0x00); + std::vector, std::optional>> cellColors(m_bytesPerRow / bytesPerCell); for (ImS64 y = m_scrollPosition; y < (m_scrollPosition + m_visibleRowCount + 5) && y < numRows && numRows != 0; y++) { // Draw address column ImGui::TableNextRow(); @@ -539,12 +541,10 @@ namespace hex::ui { const u8 validBytes = std::min(m_bytesPerRow, m_provider->getSize() - y * m_bytesPerRow); - std::vector bytes(m_bytesPerRow, 0x00); m_provider->read(y * m_bytesPerRow + m_provider->getBaseAddress() + m_provider->getCurrentPageAddress(), bytes.data(), validBytes); - std::vector, std::optional>> 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 auto cellBytes = std::min(validBytes, bytesPerCell); @@ -567,15 +567,15 @@ namespace hex::ui { foregroundColor = ImGui::GetColorU32(ImGuiCol_TextDisabled); } - cellColors.emplace_back( + cellColors[x] = { foregroundColor, backgroundColor - ); + }; } else { - cellColors.emplace_back( - std::nullopt, - std::nullopt - ); + cellColors[x] = { + std::nullopt, + std::nullopt + }; } } } @@ -634,7 +634,7 @@ namespace hex::ui { if (isCurrRegionValid(byteAddress)) this->drawCell(byteAddress, &bytes[x * bytesPerCell], bytesPerCell, cellHovered, CellType::Hex); else - ImGuiExt::TextFormatted("{}", std::string(maxCharsPerCell, '?')); + ImGuiExt::TextFormatted("{:?>{}}", "", maxCharsPerCell); if (cellHovered) { hoveredCell = { byteAddress, bytesPerCell };