From a50bb39978fdd26523c03b0fa3e477a11da8c13f Mon Sep 17 00:00:00 2001 From: WerWolv Date: Thu, 30 Nov 2023 14:40:07 +0100 Subject: [PATCH] impr: Further improve compile times --- lib/external/libromfs | 2 +- lib/external/libwolv | 2 +- lib/external/pattern_language | 2 +- .../include/hex/api/achievement_manager.hpp | 4 ++++ lib/libimhex/include/hex/api/task_manager.hpp | 14 -------------- lib/libimhex/include/hex/helpers/fmt.hpp | 1 - .../include/hex/helpers/http_requests.hpp | 6 ++++-- lib/libimhex/include/hex/helpers/logger.hpp | 18 +----------------- lib/libimhex/include/hex/helpers/utils.hpp | 6 ++++++ .../include/hex/providers/provider.hpp | 4 ++-- .../include/hex/ui/imgui_imhex_extensions.h | 16 +++++++++++----- lib/libimhex/source/api/task_manager.cpp | 15 --------------- lib/libimhex/source/helpers/logger.cpp | 19 +++++++++++++++++++ lib/libimhex/source/providers/provider.cpp | 2 ++ .../source/ui/imgui_imhex_extensions.cpp | 11 ----------- .../content/providers/disk_provider.hpp | 2 +- .../content/views/view_data_processor.hpp | 1 + .../content/command_palette_commands.cpp | 1 + .../builtin/source/content/data_inspector.cpp | 4 +++- .../builtin/source/content/pl_visualizers.cpp | 3 +++ plugins/builtin/source/content/providers.cpp | 2 +- .../content/providers/disk_provider.cpp | 2 ++ .../content/providers/file_provider.cpp | 2 +- .../providers/memory_file_provider.cpp | 2 ++ plugins/builtin/source/content/recent.cpp | 6 ++++-- .../content/views/view_pattern_editor.cpp | 5 ++++- .../providers/process_memory_provider.hpp | 4 ++-- .../providers/process_memory_provider.cpp | 12 ++++++++++++ 28 files changed, 89 insertions(+), 79 deletions(-) diff --git a/lib/external/libromfs b/lib/external/libromfs index ed311677c..04ba8ba5c 160000 --- a/lib/external/libromfs +++ b/lib/external/libromfs @@ -1 +1 @@ -Subproject commit ed311677ce042e546c433b9e1ceb41f808e5b945 +Subproject commit 04ba8ba5cdcd1365f85f62b0c2b98257c2582ae4 diff --git a/lib/external/libwolv b/lib/external/libwolv index 43ea92a66..25430e1ad 160000 --- a/lib/external/libwolv +++ b/lib/external/libwolv @@ -1 +1 @@ -Subproject commit 43ea92a66ccad58fa12b717113ded20dfa5c018f +Subproject commit 25430e1ad1b6061cd64c5afa8bb7ba71c234a22a diff --git a/lib/external/pattern_language b/lib/external/pattern_language index ae180a117..772187646 160000 --- a/lib/external/pattern_language +++ b/lib/external/pattern_language @@ -1 +1 @@ -Subproject commit ae180a117aa4513285ca6ef6072ac7de18447e61 +Subproject commit 7721876463431f9790c8e2ad0b87a37b6ab40889 diff --git a/lib/libimhex/include/hex/api/achievement_manager.hpp b/lib/libimhex/include/hex/api/achievement_manager.hpp index fdff40980..d66358a3a 100644 --- a/lib/libimhex/include/hex/api/achievement_manager.hpp +++ b/lib/libimhex/include/hex/api/achievement_manager.hpp @@ -1,9 +1,13 @@ #pragma once +#include + +#include #include #include #include #include +#include #include #include diff --git a/lib/libimhex/include/hex/api/task_manager.hpp b/lib/libimhex/include/hex/api/task_manager.hpp index 77e2b082b..49e9ce402 100644 --- a/lib/libimhex/include/hex/api/task_manager.hpp +++ b/lib/libimhex/include/hex/api/task_manager.hpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -116,11 +115,6 @@ namespace hex { std::weak_ptr m_task; }; - struct Timer { - std::chrono::time_point elapseTime; - std::function callback; - }; - /** * @brief The Task Manager is responsible for running and managing asynchronous tasks */ @@ -162,20 +156,12 @@ namespace hex { */ static void runWhenTasksFinished(const std::function &function); - /** - * @brief Creates a callback that will be executed after the given time - * @param duration Time to wait - * @param function Function to be executed - */ - static void doAfter(std::chrono::duration duration, const std::function &function); - static void collectGarbage(); static size_t getRunningTaskCount(); static size_t getRunningBackgroundTaskCount(); static std::list> &getRunningTasks(); - static std::list &getTimers(); static void runDeferredCalls(); private: diff --git a/lib/libimhex/include/hex/helpers/fmt.hpp b/lib/libimhex/include/hex/helpers/fmt.hpp index 7ef15edbf..575990a5f 100644 --- a/lib/libimhex/include/hex/helpers/fmt.hpp +++ b/lib/libimhex/include/hex/helpers/fmt.hpp @@ -2,7 +2,6 @@ #include #include -#include namespace hex { diff --git a/lib/libimhex/include/hex/helpers/http_requests.hpp b/lib/libimhex/include/hex/helpers/http_requests.hpp index ff11b5ea0..8e6f5ef91 100644 --- a/lib/libimhex/include/hex/helpers/http_requests.hpp +++ b/lib/libimhex/include/hex/helpers/http_requests.hpp @@ -10,10 +10,12 @@ #include #include -using curl_off_t = long long; - #if defined(OS_WEB) #include + + using curl_off_t = long; +#else + #include #endif typedef void CURL; diff --git a/lib/libimhex/include/hex/helpers/logger.hpp b/lib/libimhex/include/hex/helpers/logger.hpp index 6f626e103..ef056928b 100644 --- a/lib/libimhex/include/hex/helpers/logger.hpp +++ b/lib/libimhex/include/hex/helpers/logger.hpp @@ -2,12 +2,10 @@ #include -#include #include #include #include -#include #include @@ -31,21 +29,7 @@ namespace hex::log { std::vector& getLogEntries(); - [[maybe_unused]] inline void printPrefix(FILE *dest, const fmt::text_style &ts, const std::string &level) { - const auto now = fmt::localtime(std::chrono::system_clock::to_time_t(std::chrono::system_clock::now())); - - fmt::print(dest, "[{0:%H:%M:%S}] ", now); - - if (impl::isRedirected()) - fmt::print(dest, "{0} ", level); - else - fmt::print(dest, ts, "{0} ", level); - - fmt::print(dest, "[{0}] ", IMHEX_PROJECT_NAME); - - constexpr static auto ProjectNameLength = std::char_traits::length(IMHEX_PROJECT_NAME); - fmt::print(dest, "{}", std::string(ProjectNameLength > 10 ? 0 : 10 - ProjectNameLength, ' ')); - } + [[maybe_unused]] void printPrefix(FILE *dest, const fmt::text_style &ts, const std::string &level); [[maybe_unused]] void print(const fmt::text_style &ts, const std::string &level, const std::string &fmt, auto && ... args) { std::scoped_lock lock(impl::g_loggerMutex); diff --git a/lib/libimhex/include/hex/helpers/utils.hpp b/lib/libimhex/include/hex/helpers/utils.hpp index f5bd8b4fa..1701620a5 100644 --- a/lib/libimhex/include/hex/helpers/utils.hpp +++ b/lib/libimhex/include/hex/helpers/utils.hpp @@ -18,6 +18,12 @@ #include #include +#if defined(OS_MACOS) + #include +#elif defined(OS_LINUX) + #include +#endif + struct ImVec2; namespace hex { diff --git a/lib/libimhex/include/hex/providers/provider.hpp b/lib/libimhex/include/hex/providers/provider.hpp index e4ca881b7..f429393d8 100644 --- a/lib/libimhex/include/hex/providers/provider.hpp +++ b/lib/libimhex/include/hex/providers/provider.hpp @@ -12,7 +12,7 @@ #include #include -#include +#include #include @@ -207,7 +207,7 @@ namespace hex::prv { [[nodiscard]] u32 getID() const; void setID(u32 id); - [[nodiscard]] virtual nlohmann::json storeSettings(nlohmann::json settings = { }) const; + [[nodiscard]] virtual nlohmann::json storeSettings(nlohmann::json settings) const; virtual void loadSettings(const nlohmann::json &settings); void markDirty(bool dirty = true) { this->m_dirty = dirty; } diff --git a/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h b/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h index c25abcf71..dbd40d275 100644 --- a/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h +++ b/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h @@ -3,12 +3,10 @@ #include #include -#include #include #include #include -#include #include #include @@ -152,7 +150,7 @@ namespace ImGuiExt { ImVec4 GetCustomColorVec4(ImGuiCustomCol idx, float alpha_mul = 1.0F); inline ImHexCustomData::Styles& GetCustomStyle() { - auto &customData = *static_cast(GImGui->IO.UserData); + auto &customData = *static_cast(ImGui::GetIO().UserData); return customData.styles; } @@ -274,8 +272,16 @@ namespace ImGuiExt { void BeginSubWindow(const char *label, ImVec2 size = ImVec2(0, 0), ImGuiChildFlags flags = ImGuiChildFlags_None); void EndSubWindow(); - void ConfirmButtons(const char *textLeft, const char *textRight, const std::function &leftButtonCallback, const std::function &rightButtonCallback); - + void ConfirmButtons(const char *textLeft, const char *textRight, const auto &leftButtonCallback, const auto &rightButtonCallback) { + auto width = ImGui::GetWindowWidth(); + ImGui::SetCursorPosX(width / 9); + if (ImGui::Button(textLeft, ImVec2(width / 3, 0))) + leftButtonCallback(); + ImGui::SameLine(); + ImGui::SetCursorPosX(width / 9 * 5); + if (ImGui::Button(textRight, ImVec2(width / 3, 0))) + rightButtonCallback(); + } template constexpr ImGuiDataType getImGuiDataType() { if constexpr (std::same_as) return ImGuiDataType_U8; diff --git a/lib/libimhex/source/api/task_manager.cpp b/lib/libimhex/source/api/task_manager.cpp index fc21f188a..6bdef9fd9 100644 --- a/lib/libimhex/source/api/task_manager.cpp +++ b/lib/libimhex/source/api/task_manager.cpp @@ -19,7 +19,6 @@ namespace hex { std::mutex s_deferredCallsMutex, s_tasksFinishedMutex; std::list> s_tasks, s_taskQueue; - std::list s_timers; std::list> s_deferredCalls; std::list> s_tasksFinishedCallbacks; @@ -311,10 +310,6 @@ namespace hex { return s_tasks; } - std::list &TaskManager::getTimers() { - return s_timers; - } - size_t TaskManager::getRunningTaskCount() { std::unique_lock lock(s_queueMutex); @@ -345,12 +340,6 @@ namespace hex { call(); s_deferredCalls.clear(); - - for (const auto &timer : s_timers) { - if (timer.elapseTime >= std::chrono::steady_clock::now()) { - timer.callback(); - } - } } void TaskManager::runWhenTasksFinished(const std::function &function) { @@ -359,8 +348,4 @@ namespace hex { s_tasksFinishedCallbacks.push_back(function); } - void TaskManager::doAfter(std::chrono::duration duration, const std::function &function) { - s_timers.push_back({ std::chrono::steady_clock::now() + duration, function }); - } - } diff --git a/lib/libimhex/source/helpers/logger.cpp b/lib/libimhex/source/helpers/logger.cpp index 646b31c79..e870034e4 100644 --- a/lib/libimhex/source/helpers/logger.cpp +++ b/lib/libimhex/source/helpers/logger.cpp @@ -4,6 +4,9 @@ #include +#include +#include + #if defined(OS_WINDOWS) #include #endif @@ -59,6 +62,22 @@ namespace hex::log::impl { return logEntries; } + void printPrefix(FILE *dest, const fmt::text_style &ts, const std::string &level) { + const auto now = fmt::localtime(std::chrono::system_clock::to_time_t(std::chrono::system_clock::now())); + + fmt::print(dest, "[{0:%H:%M:%S}] ", now); + + if (impl::isRedirected()) + fmt::print(dest, "{0} ", level); + else + fmt::print(dest, ts, "{0} ", level); + + fmt::print(dest, "[{0}] ", IMHEX_PROJECT_NAME); + + constexpr static auto ProjectNameLength = std::char_traits::length(IMHEX_PROJECT_NAME); + fmt::print(dest, "{}", std::string(ProjectNameLength > 10 ? 0 : 10 - ProjectNameLength, ' ')); + } + void assertionHandler(bool expr, const char* exprString, const char* file, int line) { if (!expr) { log::error("Assertion failed: {} at {}:{}", exprString, file, line); diff --git a/lib/libimhex/source/providers/provider.cpp b/lib/libimhex/source/providers/provider.cpp index 1e4b633a8..eaa3a9bd4 100644 --- a/lib/libimhex/source/providers/provider.cpp +++ b/lib/libimhex/source/providers/provider.cpp @@ -10,6 +10,8 @@ #include #include +#include + namespace hex::prv { namespace { diff --git a/lib/libimhex/source/ui/imgui_imhex_extensions.cpp b/lib/libimhex/source/ui/imgui_imhex_extensions.cpp index 2b7ab05be..3e2f5540a 100644 --- a/lib/libimhex/source/ui/imgui_imhex_extensions.cpp +++ b/lib/libimhex/source/ui/imgui_imhex_extensions.cpp @@ -917,17 +917,6 @@ namespace ImGuiExt { ImGui::EndChild(); } - void ConfirmButtons(const char *textLeft, const char *textRight, const std::function &leftButtonCallback, const std::function &rightButtonCallback) { - auto width = ImGui::GetWindowWidth(); - ImGui::SetCursorPosX(width / 9); - if (ImGui::Button(textLeft, ImVec2(width / 3, 0))) - leftButtonCallback(); - ImGui::SameLine(); - ImGui::SetCursorPosX(width / 9 * 5); - if (ImGui::Button(textRight, ImVec2(width / 3, 0))) - rightButtonCallback(); - } - } namespace ImGui { diff --git a/plugins/builtin/include/content/providers/disk_provider.hpp b/plugins/builtin/include/content/providers/disk_provider.hpp index ac46d6698..f3728c205 100644 --- a/plugins/builtin/include/content/providers/disk_provider.hpp +++ b/plugins/builtin/include/content/providers/disk_provider.hpp @@ -36,7 +36,7 @@ namespace hex::plugin::builtin { bool drawLoadInterface() override; void loadSettings(const nlohmann::json &settings) override; - [[nodiscard]] nlohmann::json storeSettings(nlohmann::json settings = { }) const override; + [[nodiscard]] nlohmann::json storeSettings(nlohmann::json settings) const override; [[nodiscard]] std::string getTypeName() const override { return "hex.builtin.provider.disk"; diff --git a/plugins/builtin/include/content/views/view_data_processor.hpp b/plugins/builtin/include/content/views/view_data_processor.hpp index b22555215..dd3015123 100644 --- a/plugins/builtin/include/content/views/view_data_processor.hpp +++ b/plugins/builtin/include/content/views/view_data_processor.hpp @@ -8,6 +8,7 @@ #include #include +#include namespace hex::plugin::builtin { diff --git a/plugins/builtin/source/content/command_palette_commands.cpp b/plugins/builtin/source/content/command_palette_commands.cpp index fabd81d83..2db920ac7 100644 --- a/plugins/builtin/source/content/command_palette_commands.cpp +++ b/plugins/builtin/source/content/command_palette_commands.cpp @@ -1,6 +1,7 @@ #include #include +#include #include #include diff --git a/plugins/builtin/source/content/data_inspector.cpp b/plugins/builtin/source/content/data_inspector.cpp index 825ae657c..c8ce55c36 100644 --- a/plugins/builtin/source/content/data_inspector.cpp +++ b/plugins/builtin/source/content/data_inspector.cpp @@ -2,9 +2,11 @@ #include #include -#include #include +#include +#include + #include #include diff --git a/plugins/builtin/source/content/pl_visualizers.cpp b/plugins/builtin/source/content/pl_visualizers.cpp index a0d1dd349..a06f3eeb1 100644 --- a/plugins/builtin/source/content/pl_visualizers.cpp +++ b/plugins/builtin/source/content/pl_visualizers.cpp @@ -7,6 +7,9 @@ #include #include +#include +#include + #include #include diff --git a/plugins/builtin/source/content/providers.cpp b/plugins/builtin/source/content/providers.cpp index 9950231ae..e62c24d16 100644 --- a/plugins/builtin/source/content/providers.cpp +++ b/plugins/builtin/source/content/providers.cpp @@ -119,7 +119,7 @@ namespace hex::plugin::builtin { nlohmann::json json; json["type"] = provider->getTypeName(); - json["settings"] = provider->storeSettings(); + json["settings"] = provider->storeSettings({}); tar.writeString(basePath / hex::format("{}.json", id), json.dump(4)); } diff --git a/plugins/builtin/source/content/providers/disk_provider.cpp b/plugins/builtin/source/content/providers/disk_provider.cpp index 654cb2446..9bd7d49cb 100644 --- a/plugins/builtin/source/content/providers/disk_provider.cpp +++ b/plugins/builtin/source/content/providers/disk_provider.cpp @@ -16,6 +16,8 @@ #include +#include + #if defined(OS_WINDOWS) #include #include diff --git a/plugins/builtin/source/content/providers/file_provider.cpp b/plugins/builtin/source/content/providers/file_provider.cpp index 2005bd542..fd3dc96d8 100644 --- a/plugins/builtin/source/content/providers/file_provider.cpp +++ b/plugins/builtin/source/content/providers/file_provider.cpp @@ -8,9 +8,9 @@ #include #include - #include #include +#include #include diff --git a/plugins/builtin/source/content/providers/memory_file_provider.cpp b/plugins/builtin/source/content/providers/memory_file_provider.cpp index 50ba203e0..0f1545fc5 100644 --- a/plugins/builtin/source/content/providers/memory_file_provider.cpp +++ b/plugins/builtin/source/content/providers/memory_file_provider.cpp @@ -10,6 +10,8 @@ #include +#include + namespace hex::plugin::builtin { bool MemoryFileProvider::open() { diff --git a/plugins/builtin/source/content/recent.cpp b/plugins/builtin/source/content/recent.cpp index a41f8abab..e885f3b88 100644 --- a/plugins/builtin/source/content/recent.cpp +++ b/plugins/builtin/source/content/recent.cpp @@ -6,9 +6,11 @@ #include #include #include -#include #include +#include +#include + #include #include @@ -48,7 +50,7 @@ namespace hex::plugin::builtin::recent { auto path = ProjectFile::getPath(); ProjectFile::clearPath(); - if (auto settings = provider->storeSettings(); !settings.is_null()) + if (auto settings = provider->storeSettings({}); !settings.is_null()) recentFile.writeString(settings.dump(4)); ProjectFile::setPath(path); diff --git a/plugins/builtin/source/content/views/view_pattern_editor.cpp b/plugins/builtin/source/content/views/view_pattern_editor.cpp index d2e9c6c63..9ef69f046 100644 --- a/plugins/builtin/source/content/views/view_pattern_editor.cpp +++ b/plugins/builtin/source/content/views/view_pattern_editor.cpp @@ -16,6 +16,9 @@ #include #include +#include +#include + #include #include @@ -1052,7 +1055,7 @@ namespace hex::plugin::builtin { std::scoped_lock lock(this->m_logMutex); this->m_console->emplace_back( - hex::format("I: Evaluation took {}", runtime.getLastRunningTime()) + hex::format("I: Evaluation took {}", std::chrono::duration(runtime.getLastRunningTime())) ); this->m_consoleNeedsUpdate = true; }; diff --git a/plugins/windows/include/content/providers/process_memory_provider.hpp b/plugins/windows/include/content/providers/process_memory_provider.hpp index bb15bd99d..70992f23a 100644 --- a/plugins/windows/include/content/providers/process_memory_provider.hpp +++ b/plugins/windows/include/content/providers/process_memory_provider.hpp @@ -51,8 +51,8 @@ namespace hex::plugin::windows { bool drawLoadInterface() override; void drawInterface() override; - void loadSettings(const nlohmann::json &) override {} - [[nodiscard]] nlohmann::json storeSettings(nlohmann::json) const override { return { }; } + void loadSettings(const nlohmann::json &) override; + [[nodiscard]] nlohmann::json storeSettings(nlohmann::json) const override; [[nodiscard]] std::string getTypeName() const override { return "hex.windows.provider.process_memory"; diff --git a/plugins/windows/source/content/providers/process_memory_provider.cpp b/plugins/windows/source/content/providers/process_memory_provider.cpp index 65ca2b42c..5b3bec77a 100644 --- a/plugins/windows/source/content/providers/process_memory_provider.cpp +++ b/plugins/windows/source/content/providers/process_memory_provider.cpp @@ -12,6 +12,8 @@ #include +#include + namespace hex::plugin::windows { bool ProcessMemoryProvider::open() { @@ -300,4 +302,14 @@ namespace hex::plugin::windows { return Provider::queryInformation(category, argument); } + void ProcessMemoryProvider::loadSettings(const nlohmann::json&) { + + } + + nlohmann::json ProcessMemoryProvider::storeSettings(nlohmann::json) const { + return {}; + } + + + } \ No newline at end of file