diff --git a/CMakeLists.txt b/CMakeLists.txt index fdf9c8e..4d382cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,7 @@ option(OMATH_SUPRESS_SAFETY_CHECKS "Supress some safety checks in release build option(OMATH_USE_UNITY_BUILD "Will enable unity build to speed up compilation" OFF) option(OMATH_ENABLE_LEGACY "Will enable legacy classes that MUST be used ONLY for backward compatibility" ON) option(OMATH_ENABLE_COVERAGE "Enable coverage" OFF) - +option(OMATH_ENABLE_FORCE_INLINE "Will for compiler to make some functions to be force inlined no matter what" ON) if (VCPKG_MANIFEST_FEATURES) foreach (omath_feature IN LISTS VCPKG_MANIFEST_FEATURES) if (omath_feature STREQUAL "imgui") @@ -112,6 +112,10 @@ if (OMATH_ENABLE_LEGACY) target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_ENABLE_LEGACY) endif () +if (OMATH_ENABLE_FORCE_INLINE) + target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_ENABLE_FORCE_INLINE) +endif () + set_target_properties(${PROJECT_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}" LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}" diff --git a/include/omath/containers/encrypted_variable.hpp b/include/omath/containers/encrypted_variable.hpp index 158fb21..633fa79 100644 --- a/include/omath/containers/encrypted_variable.hpp +++ b/include/omath/containers/encrypted_variable.hpp @@ -6,11 +6,14 @@ #include #include #include - +#ifdef OMATH_ENABLE_FORCE_INLINE #ifdef _MSC_VER -#define OMATH_FORCEINLINE __forceinline +#define OMATH_FORCE_INLINE __forceinline #else -#define OMATH_FORCEINLINE __attribute__((always_inline)) inline +#define OMATH_FORCE_INLINE __attribute__((always_inline)) inline +#endif +#else +#define OMATH_FORCE_INLINE #endif namespace omath::detail @@ -111,7 +114,7 @@ namespace omath bool m_is_encrypted; T m_data; - OMATH_FORCEINLINE constexpr void xor_contained_var_by_key() + OMATH_FORCE_INLINE constexpr void xor_contained_var_by_key() { std::span bytes{reinterpret_cast(&m_data), sizeof(m_data)}; @@ -121,7 +124,7 @@ namespace omath } public: - OMATH_FORCEINLINE constexpr explicit EncryptedVariable(const T& data): m_is_encrypted(false), m_data(data) + OMATH_FORCE_INLINE constexpr explicit EncryptedVariable(const T& data): m_is_encrypted(false), m_data(data) { encrypt(); } @@ -129,14 +132,14 @@ namespace omath { return m_is_encrypted; } - OMATH_FORCEINLINE constexpr void decrypt() + OMATH_FORCE_INLINE constexpr void decrypt() { if (!m_is_encrypted) return; xor_contained_var_by_key(); m_is_encrypted = false; } - OMATH_FORCEINLINE constexpr void encrypt() + OMATH_FORCE_INLINE constexpr void encrypt() { if (m_is_encrypted) return; @@ -144,21 +147,21 @@ namespace omath m_is_encrypted = true; } [[nodiscard]] - OMATH_FORCEINLINE constexpr T& value() + OMATH_FORCE_INLINE constexpr T& value() { return m_data; } [[nodiscard]] - OMATH_FORCEINLINE constexpr const T& value() const + OMATH_FORCE_INLINE constexpr const T& value() const { return m_data; } - OMATH_FORCEINLINE ~EncryptedVariable() + OMATH_FORCE_INLINE ~EncryptedVariable() { decrypt(); } [[nodiscard]] - OMATH_FORCEINLINE auto drop_anchor() + OMATH_FORCE_INLINE auto drop_anchor() { return VarAnchor{*this}; } @@ -168,11 +171,11 @@ namespace omath { public: // ReSharper disable once CppNonExplicitConvertingConstructor - OMATH_FORCEINLINE constexpr VarAnchor(EncryptedVarType& var): m_var(var) // NOLINT(*-explicit-constructor) + OMATH_FORCE_INLINE constexpr VarAnchor(EncryptedVarType& var): m_var(var) // NOLINT(*-explicit-constructor) { m_var.decrypt(); } - OMATH_FORCEINLINE constexpr ~VarAnchor() + OMATH_FORCE_INLINE constexpr ~VarAnchor() { m_var.encrypt(); }