Skip to content

Commit d2e418c

Browse files
committed
added cmake option
1 parent eae10d9 commit d2e418c

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ option(OMATH_SUPRESS_SAFETY_CHECKS "Supress some safety checks in release build
2727
option(OMATH_USE_UNITY_BUILD "Will enable unity build to speed up compilation" OFF)
2828
option(OMATH_ENABLE_LEGACY "Will enable legacy classes that MUST be used ONLY for backward compatibility" ON)
2929
option(OMATH_ENABLE_COVERAGE "Enable coverage" OFF)
30-
30+
option(OMATH_ENABLE_FORCE_INLINE "Will for compiler to make some functions to be force inlined no matter what" ON)
3131
if (VCPKG_MANIFEST_FEATURES)
3232
foreach (omath_feature IN LISTS VCPKG_MANIFEST_FEATURES)
3333
if (omath_feature STREQUAL "imgui")
@@ -112,6 +112,10 @@ if (OMATH_ENABLE_LEGACY)
112112
target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_ENABLE_LEGACY)
113113
endif ()
114114

115+
if (OMATH_ENABLE_FORCE_INLINE)
116+
target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_ENABLE_FORCE_INLINE)
117+
endif ()
118+
115119
set_target_properties(${PROJECT_NAME} PROPERTIES
116120
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"
117121
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}"

include/omath/containers/encrypted_variable.hpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
#include <cstddef>
77
#include <cstdint>
88
#include <span>
9-
9+
#ifdef OMATH_ENABLE_FORCE_INLINE
1010
#ifdef _MSC_VER
11-
#define OMATH_FORCEINLINE __forceinline
11+
#define OMATH_FORCE_INLINE __forceinline
12+
#else
13+
#define OMATH_FORCE_INLINE __attribute__((always_inline)) inline
14+
#endif
1215
#else
13-
#define OMATH_FORCEINLINE __attribute__((always_inline)) inline
16+
#define OMATH_FORCE_INLINE
1417
#endif
1518

1619
namespace omath::detail
@@ -111,7 +114,7 @@ namespace omath
111114
bool m_is_encrypted;
112115
T m_data;
113116

114-
OMATH_FORCEINLINE constexpr void xor_contained_var_by_key()
117+
OMATH_FORCE_INLINE constexpr void xor_contained_var_by_key()
115118
{
116119
std::span bytes{reinterpret_cast<std::uint8_t*>(&m_data), sizeof(m_data)};
117120

@@ -121,44 +124,44 @@ namespace omath
121124
}
122125

123126
public:
124-
OMATH_FORCEINLINE constexpr explicit EncryptedVariable(const T& data): m_is_encrypted(false), m_data(data)
127+
OMATH_FORCE_INLINE constexpr explicit EncryptedVariable(const T& data): m_is_encrypted(false), m_data(data)
125128
{
126129
encrypt();
127130
}
128131
[[nodiscard]] constexpr bool is_encrypted() const
129132
{
130133
return m_is_encrypted;
131134
}
132-
OMATH_FORCEINLINE constexpr void decrypt()
135+
OMATH_FORCE_INLINE constexpr void decrypt()
133136
{
134137
if (!m_is_encrypted)
135138
return;
136139
xor_contained_var_by_key();
137140
m_is_encrypted = false;
138141
}
139-
OMATH_FORCEINLINE constexpr void encrypt()
142+
OMATH_FORCE_INLINE constexpr void encrypt()
140143
{
141144
if (m_is_encrypted)
142145
return;
143146
xor_contained_var_by_key();
144147
m_is_encrypted = true;
145148
}
146149
[[nodiscard]]
147-
OMATH_FORCEINLINE constexpr T& value()
150+
OMATH_FORCE_INLINE constexpr T& value()
148151
{
149152
return m_data;
150153
}
151154
[[nodiscard]]
152-
OMATH_FORCEINLINE constexpr const T& value() const
155+
OMATH_FORCE_INLINE constexpr const T& value() const
153156
{
154157
return m_data;
155158
}
156-
OMATH_FORCEINLINE ~EncryptedVariable()
159+
OMATH_FORCE_INLINE ~EncryptedVariable()
157160
{
158161
decrypt();
159162
}
160163
[[nodiscard]]
161-
OMATH_FORCEINLINE auto drop_anchor()
164+
OMATH_FORCE_INLINE auto drop_anchor()
162165
{
163166
return VarAnchor{*this};
164167
}
@@ -168,11 +171,11 @@ namespace omath
168171
{
169172
public:
170173
// ReSharper disable once CppNonExplicitConvertingConstructor
171-
OMATH_FORCEINLINE constexpr VarAnchor(EncryptedVarType& var): m_var(var) // NOLINT(*-explicit-constructor)
174+
OMATH_FORCE_INLINE constexpr VarAnchor(EncryptedVarType& var): m_var(var) // NOLINT(*-explicit-constructor)
172175
{
173176
m_var.decrypt();
174177
}
175-
OMATH_FORCEINLINE constexpr ~VarAnchor()
178+
OMATH_FORCE_INLINE constexpr ~VarAnchor()
176179
{
177180
m_var.encrypt();
178181
}

0 commit comments

Comments
 (0)