1
0
mirror of synced 2024-11-28 01:20:51 +01:00

sys: Make sure constexpr variables don't get copied onto the stack

This commit is contained in:
WerWolv 2022-09-12 21:28:02 +02:00
parent 7e3601989a
commit aa658b7dbc
14 changed files with 29 additions and 29 deletions

View File

@ -179,10 +179,10 @@ namespace hex {
return result;
}
static constexpr auto CTRL = Key(static_cast<Keys>(0x1000'0000));
static constexpr auto ALT = Key(static_cast<Keys>(0x2000'0000));
static constexpr auto SHIFT = Key(static_cast<Keys>(0x4000'0000));
static constexpr auto SUPER = Key(static_cast<Keys>(0x8000'0000));
constexpr static auto CTRL = Key(static_cast<Keys>(0x1000'0000));
constexpr static auto ALT = Key(static_cast<Keys>(0x2000'0000));
constexpr static auto SHIFT = Key(static_cast<Keys>(0x4000'0000));
constexpr static auto SUPER = Key(static_cast<Keys>(0x8000'0000));
class ShortcutManager {
public:

View File

@ -31,7 +31,7 @@ namespace hex {
class Disassembler {
public:
static constexpr cs_arch toCapstoneArchitecture(Architecture architecture) {
constexpr static cs_arch toCapstoneArchitecture(Architecture architecture) {
return static_cast<cs_arch>(architecture);
}

View File

@ -35,7 +35,7 @@ namespace hex {
Net();
~Net();
static constexpr u32 DefaultTimeout = 2'000;
constexpr static u32 DefaultTimeout = 2'000;
std::future<Response<std::string>> getString(const std::string &url, u32 timeout = DefaultTimeout);
std::future<Response<nlohmann::json>> getJson(const std::string &url, u32 timeout = DefaultTimeout);

View File

@ -233,7 +233,7 @@ namespace hex {
}
std::string toEngineeringString(double value) {
constexpr std::array Suffixes = { "a", "f", "p", "n", "u", "m", "", "k", "M", "G", "T", "P", "E" };
constexpr static std::array Suffixes = { "a", "f", "p", "n", "u", "m", "", "k", "M", "G", "T", "P", "E" };
int8_t suffixIndex = 6;

View File

@ -106,11 +106,11 @@ namespace hex {
return HTNOWHERE;
}
constexpr auto RegionClient = 0b0000;
constexpr auto RegionLeft = 0b0001;
constexpr auto RegionRight = 0b0010;
constexpr auto RegionTop = 0b0100;
constexpr auto RegionBottom = 0b1000;
constexpr static auto RegionClient = 0b0000;
constexpr static auto RegionLeft = 0b0001;
constexpr static auto RegionRight = 0b0010;
constexpr static auto RegionTop = 0b0100;
constexpr static auto RegionBottom = 0b1000;
const auto result =
RegionLeft * (cursor.x < (window.left + border.x)) |

View File

@ -129,7 +129,7 @@ namespace hex {
glfwSetWindowTitle(this->m_window, title.c_str());
});
constexpr auto CrashBackupFileName = "crash_backup.hexproj";
constexpr static auto CrashBackupFileName = "crash_backup.hexproj";
EventManager::subscribe<EventAbnormalTermination>(this, [this, CrashBackupFileName](int) {
ImGui::SaveIniSettingsToDisk(this->m_imguiSettingsPath.string().c_str());

View File

@ -32,7 +32,7 @@ namespace hex::plugin::builtin {
NodeBuffer() : Node("hex.builtin.nodes.constants.buffer.header", { dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "") }) { }
void drawNode() override {
constexpr int StepSize = 1, FastStepSize = 10;
constexpr static int StepSize = 1, FastStepSize = 10;
ImGui::PushItemWidth(100);
ImGui::InputScalar("hex.builtin.nodes.constants.buffer.size"_lang, ImGuiDataType_U32, &this->m_size, &StepSize, &FastStepSize);

View File

@ -29,8 +29,8 @@ namespace hex {
namespace {
constexpr auto DisplayEndDefault = 50u;
constexpr auto DisplayEndStep = 50u;
constexpr auto DisplayEndDefault = 50U;
constexpr auto DisplayEndStep = 50U;
using namespace ::std::literals::string_literals;

View File

@ -974,7 +974,7 @@ namespace hex::plugin::builtin {
return;
}
constexpr auto BufferSize = 0xFF'FFFF;
constexpr static auto BufferSize = 0xFF'FFFF;
for (u64 partOffset = 0; partOffset < splitSize; partOffset += BufferSize) {
partFile.write(file.readBytes(std::min<u64>(BufferSize, splitSize - partOffset)));
partFile.flush();
@ -1103,7 +1103,7 @@ namespace hex::plugin::builtin {
return;
}
constexpr auto BufferSize = 0xFF'FFFF;
constexpr static auto BufferSize = 0xFF'FFFF;
auto inputSize = input.getSize();
for (u64 inputOffset = 0; inputOffset < inputSize; inputOffset += BufferSize) {
output.write(input.readBytes(std::min<u64>(BufferSize, inputSize - inputOffset)));

View File

@ -147,7 +147,7 @@ namespace hex::plugin::builtin {
ImGui::TableSetupColumn("Type");
ImGui::TableSetupColumn("Paths");
constexpr std::array<std::pair<const char *, fs::ImHexPath>, 8> PathTypes = {
constexpr static std::array<std::pair<const char *, fs::ImHexPath>, 8> PathTypes = {
{{ "Resources", fs::ImHexPath::Resources },
{ "Config", fs::ImHexPath::Config },
{ "Magic", fs::ImHexPath::Magic },

View File

@ -75,7 +75,7 @@ namespace hex::plugin::builtin {
}
std::vector<ViewCommandPalette::CommandResult> ViewCommandPalette::getCommandResults(const std::string &input) {
constexpr auto MatchCommand = [](const std::string &currCommand, const std::string &commandToMatch) -> std::pair<MatchType, std::string_view> {
constexpr static auto MatchCommand = [](const std::string &currCommand, const std::string &commandToMatch) -> std::pair<MatchType, std::string_view> {
if (currCommand.empty()) {
return { MatchType::InfoMatch, "" };
} else if (currCommand.size() <= commandToMatch.size()) {

View File

@ -1002,14 +1002,14 @@ namespace hex::plugin::builtin {
if ((ImGui::IsMouseDown(ImGuiMouseButton_Left) && this->m_selectionStart != this->m_selectionEnd)) {
auto fractionPerLine = 1.0 / (this->m_visibleRowCount + 1);
if (y == u64(clipper.DisplayStart + 2)) {
if (i128(this->m_selectionEnd - provider->getBaseAddress() - provider->getCurrentPageAddress()) <= (i64(clipper.DisplayStart + 2) * this->m_bytesPerRow)) {
if (y == u64(clipper.DisplayStart + 3)) {
if (i128(this->m_selectionEnd - provider->getBaseAddress() - provider->getCurrentPageAddress()) <= (i64(clipper.DisplayStart + 3) * this->m_bytesPerRow)) {
this->m_shouldScrollToSelection = false;
ImGui::SetScrollHereY(fractionPerLine * 4);
ImGui::SetScrollHereY(fractionPerLine * 5);
}
} else if (y == u64(clipper.DisplayEnd - 2)) {
if (i128(this->m_selectionEnd - provider->getBaseAddress() - provider->getCurrentPageAddress()) >= (i64(clipper.DisplayEnd - 2) * this->m_bytesPerRow)) {
} else if (y == u64(clipper.DisplayEnd - 3)) {
if (i128(this->m_selectionEnd - provider->getBaseAddress() - provider->getCurrentPageAddress()) >= (i64(clipper.DisplayEnd - 3) * this->m_bytesPerRow)) {
this->m_shouldScrollToSelection = false;
ImGui::SetScrollHereY(fractionPerLine * (this->m_visibleRowCount - 1));
}

View File

@ -26,13 +26,13 @@ namespace hex::plugin::builtin {
static bool initialized = false;
static TextEditor::LanguageDefinition langDef;
if (!initialized) {
static constexpr std::array keywords = {
constexpr static std::array keywords = {
"using", "struct", "union", "enum", "bitfield", "be", "le", "if", "else", "false", "true", "this", "parent", "addressof", "sizeof", "$", "while", "for", "fn", "return", "break", "continue", "namespace", "in", "out"
};
for (auto &k : keywords)
langDef.mKeywords.insert(k);
static constexpr std::array builtInTypes = {
constexpr static std::array builtInTypes = {
"u8", "u16", "u24", "u32", "u48", "u64", "u96", "u128", "s8", "s16", "s24", "s32", "s48", "s64", "s96", "s128", "float", "double", "char", "char16", "bool", "padding", "str", "auto"
};
for (const auto name : builtInTypes) {
@ -524,7 +524,7 @@ namespace hex::plugin::builtin {
ON_SCOPE_EXIT { ImGui::PopID(); };
ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x);
constexpr const char *Types[] = { "I", "F", "S", "B" };
constexpr static const char *Types[] = { "I", "F", "S", "B" };
if (ImGui::BeginCombo("", Types[static_cast<int>(type)])) {
for (auto i = 0; i < IM_ARRAYSIZE(Types); i++) {
if (ImGui::Selectable(Types[i]))

View File

@ -528,7 +528,7 @@ namespace hex::plugin::builtin {
});
constexpr auto CrashBackupFileName = "crash_backup.hexproj";
constexpr static auto CrashBackupFileName = "crash_backup.hexproj";
for (const auto &path : fs::getDefaultPaths(fs::ImHexPath::Config)) {
if (auto filePath = std::fs::path(path) / CrashBackupFileName; fs::exists(filePath)) {
s_safetyBackupPath = filePath;