1
0
mirror of synced 2024-09-24 03:28:24 +02:00

impr: Further improve compile times

This commit is contained in:
WerWolv 2023-11-30 14:40:07 +01:00
parent 8ee234e5a6
commit a50bb39978
28 changed files with 89 additions and 79 deletions

@ -1 +1 @@
Subproject commit ed311677ce042e546c433b9e1ceb41f808e5b945
Subproject commit 04ba8ba5cdcd1365f85f62b0c2b98257c2582ae4

@ -1 +1 @@
Subproject commit 43ea92a66ccad58fa12b717113ded20dfa5c018f
Subproject commit 25430e1ad1b6061cd64c5afa8bb7ba71c234a22a

@ -1 +1 @@
Subproject commit ae180a117aa4513285ca6ef6072ac7de18447e61
Subproject commit 7721876463431f9790c8e2ad0b87a37b6ab40889

View File

@ -1,9 +1,13 @@
#pragma once
#include <hex.hpp>
#include <functional>
#include <list>
#include <memory>
#include <span>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

View File

@ -6,7 +6,6 @@
#include <thread>
#include <functional>
#include <mutex>
#include <chrono>
#include <memory>
#include <list>
#include <condition_variable>
@ -116,11 +115,6 @@ namespace hex {
std::weak_ptr<Task> m_task;
};
struct Timer {
std::chrono::time_point<std::chrono::steady_clock> elapseTime;
std::function<void()> 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<void()> &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<i64> duration, const std::function<void()> &function);
static void collectGarbage();
static size_t getRunningTaskCount();
static size_t getRunningBackgroundTaskCount();
static std::list<std::shared_ptr<Task>> &getRunningTasks();
static std::list<Timer> &getTimers();
static void runDeferredCalls();
private:

View File

@ -2,7 +2,6 @@
#include <string_view>
#include <fmt/format.h>
#include <fmt/chrono.h>
namespace hex {

View File

@ -10,10 +10,12 @@
#include <wolv/io/file.hpp>
#include <wolv/utils/guards.hpp>
using curl_off_t = long long;
#if defined(OS_WEB)
#include <emscripten/fetch.h>
using curl_off_t = long;
#else
#include <curl/curl.h>
#endif
typedef void CURL;

View File

@ -2,12 +2,10 @@
#include <hex.hpp>
#include <chrono>
#include <mutex>
#include <fmt/core.h>
#include <fmt/color.h>
#include <fmt/chrono.h>
#include <wolv/io/file.hpp>
@ -31,21 +29,7 @@ namespace hex::log {
std::vector<LogEntry>& 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<char>::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);

View File

@ -18,6 +18,12 @@
#include <variant>
#include <vector>
#if defined(OS_MACOS)
#include <hex/helpers/utils_macos.hpp>
#elif defined(OS_LINUX)
#include <hex/helpers/utils_linux.hpp>
#endif
struct ImVec2;
namespace hex {

View File

@ -12,7 +12,7 @@
#include <hex/providers/overlay.hpp>
#include <hex/helpers/fs.hpp>
#include <nlohmann/json.hpp>
#include <nlohmann/json_fwd.hpp>
#include <hex/providers/undo_redo/stack.hpp>
@ -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; }

View File

@ -3,12 +3,10 @@
#include <hex.hpp>
#include <cstddef>
#include <functional>
#include <string>
#include <span>
#include <imgui.h>
#include <imgui_internal.h>
#include <hex/helpers/fmt.hpp>
#include <hex/helpers/concepts.hpp>
@ -152,7 +150,7 @@ namespace ImGuiExt {
ImVec4 GetCustomColorVec4(ImGuiCustomCol idx, float alpha_mul = 1.0F);
inline ImHexCustomData::Styles& GetCustomStyle() {
auto &customData = *static_cast<ImHexCustomData *>(GImGui->IO.UserData);
auto &customData = *static_cast<ImHexCustomData *>(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<void()> &leftButtonCallback, const std::function<void()> &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<typename T>
constexpr ImGuiDataType getImGuiDataType() {
if constexpr (std::same_as<T, u8>) return ImGuiDataType_U8;

View File

@ -19,7 +19,6 @@ namespace hex {
std::mutex s_deferredCallsMutex, s_tasksFinishedMutex;
std::list<std::shared_ptr<Task>> s_tasks, s_taskQueue;
std::list<Timer> s_timers;
std::list<std::function<void()>> s_deferredCalls;
std::list<std::function<void()>> s_tasksFinishedCallbacks;
@ -311,10 +310,6 @@ namespace hex {
return s_tasks;
}
std::list<Timer> &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<void()> &function) {
@ -359,8 +348,4 @@ namespace hex {
s_tasksFinishedCallbacks.push_back(function);
}
void TaskManager::doAfter(std::chrono::duration<i64> duration, const std::function<void()> &function) {
s_timers.push_back({ std::chrono::steady_clock::now() + duration, function });
}
}

View File

@ -4,6 +4,9 @@
#include <wolv/io/file.hpp>
#include <chrono>
#include <fmt/chrono.h>
#if defined(OS_WINDOWS)
#include <Windows.h>
#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<char>::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);

View File

@ -10,6 +10,8 @@
#include <hex/helpers/magic.hpp>
#include <wolv/io/file.hpp>
#include <nlohmann/json.hpp>
namespace hex::prv {
namespace {

View File

@ -917,17 +917,6 @@ namespace ImGuiExt {
ImGui::EndChild();
}
void ConfirmButtons(const char *textLeft, const char *textRight, const std::function<void()> &leftButtonCallback, const std::function<void()> &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 {

View File

@ -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";

View File

@ -8,6 +8,7 @@
#include <imnodes_internal.h>
#include <string>
#include <nlohmann/json.hpp>
namespace hex::plugin::builtin {

View File

@ -1,6 +1,7 @@
#include <hex/api/content_registry.hpp>
#include <hex/api/localization_manager.hpp>
#include <hex/api/shortcut_manager.hpp>
#include <hex/helpers/utils.hpp>
#include <hex/helpers/fmt.hpp>

View File

@ -2,9 +2,11 @@
#include <hex/api/content_registry.hpp>
#include <hex/helpers/utils.hpp>
#include <hex/helpers/fmt.hpp>
#include <hex/helpers/crypto.hpp>
#include <hex/helpers/fmt.hpp>
#include <fmt/chrono.h>
#include <hex/providers/provider.hpp>
#include <cstring>

View File

@ -7,6 +7,9 @@
#include <hex/helpers/utils.hpp>
#include <hex/helpers/opengl.hpp>
#include <hex/helpers/fmt.hpp>
#include <fmt/chrono.h>
#include <imgui.h>
#include <implot.h>

View File

@ -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));
}

View File

@ -16,6 +16,8 @@
#include <imgui.h>
#include <nlohmann/json.hpp>
#if defined(OS_WINDOWS)
#include <windows.h>
#include <winioctl.h>

View File

@ -8,9 +8,9 @@
#include <hex/api/project_file_manager.hpp>
#include <hex/api/task_manager.hpp>
#include <hex/helpers/utils.hpp>
#include <hex/helpers/fmt.hpp>
#include <fmt/chrono.h>
#include <wolv/utils/string.hpp>

View File

@ -10,6 +10,8 @@
#include <wolv/io/file.hpp>
#include <nlohmann/json.hpp>
namespace hex::plugin::builtin {
bool MemoryFileProvider::open() {

View File

@ -6,9 +6,11 @@
#include <hex/api/content_registry.hpp>
#include <hex/api/project_file_manager.hpp>
#include <hex/api/task_manager.hpp>
#include <hex/helpers/fmt.hpp>
#include <hex/providers/provider.hpp>
#include <hex/helpers/fmt.hpp>
#include <fmt/chrono.h>
#include <wolv/utils/guards.hpp>
#include <wolv/utils/string.hpp>
@ -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);

View File

@ -16,6 +16,9 @@
#include <hex/helpers/magic.hpp>
#include <hex/helpers/binary_pattern.hpp>
#include <hex/helpers/fmt.hpp>
#include <fmt/chrono.h>
#include <content/popups/popup_file_chooser.hpp>
#include <content/popups/popup_question.hpp>
@ -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<double>(runtime.getLastRunningTime()))
);
this->m_consoleNeedsUpdate = true;
};

View File

@ -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";

View File

@ -12,6 +12,8 @@
#include <wolv/utils/guards.hpp>
#include <nlohmann/json.hpp>
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 {};
}
}