Disabling some of MSVC most aggressive Debug runtime checks for some simple/low-level functions

(e.g. ImVec2, ImVector) leading to a 10-20% increase of performances with MSVC "default" Debug settings.
This commit is contained in:
ocornut
2021-05-06 12:40:03 +02:00
parent 393941ceea
commit 84545dbe6f
3 changed files with 21 additions and 0 deletions

13
imgui.h
View File

@ -100,6 +100,15 @@ Index of this file:
#define IM_FMTLIST(FMT)
#endif
// Disable some of MSVC most aggressive Debug runtime checks in function header/footer (used in some simple/low-level functions)
#if defined(_MSC_VER) && !defined(__clang__) && !defined(IMGUI_DEBUG_PARANOID)
#define IM_MSVC_RUNTIME_CHECKS_OFF __pragma(runtime_checks("",off)) __pragma(check_stack(off)) __pragma(strict_gs_check(push,off))
#define IM_MSVC_RUNTIME_CHECKS_RESTORE __pragma(runtime_checks("",restore)) __pragma(check_stack()) __pragma(strict_gs_check(pop))
#else
#define IM_MSVC_RUNTIME_CHECKS_OFF
#define IM_MSVC_RUNTIME_CHECKS_RESTORE
#endif
// Warnings
#ifdef _MSC_VER
#pragma warning (push)
@ -231,6 +240,7 @@ typedef unsigned long long ImU64; // 64-bit unsigned integer (post C++11)
#endif
// 2D vector (often used to store positions or sizes)
IM_MSVC_RUNTIME_CHECKS_OFF
struct ImVec2
{
float x, y;
@ -253,6 +263,7 @@ struct ImVec4
IM_VEC4_CLASS_EXTRA // Define additional constructors and implicit cast operators in imconfig.h to convert back and forth between your math types and ImVec4.
#endif
};
IM_MSVC_RUNTIME_CHECKS_RESTORE
//-----------------------------------------------------------------------------
// [SECTION] Dear ImGui end-user API functions
@ -1637,6 +1648,7 @@ template<typename T> void IM_DELETE(T* p) { if (p) { p->~T(); ImGui::MemFree(p
// Do NOT use this class as a std::vector replacement in your own code! Many of the structures used by dear imgui can be safely initialized by a zero-memset.
//-----------------------------------------------------------------------------
IM_MSVC_RUNTIME_CHECKS_OFF
template<typename T>
struct ImVector
{
@ -1695,6 +1707,7 @@ struct ImVector
inline bool find_erase_unsorted(const T& v) { const T* it = find(v); if (it < Data + Size) { erase_unsorted(it); return true; } return false; }
inline int index_from_ptr(const T* it) const { IM_ASSERT(it >= Data && it < Data + Size); const ptrdiff_t off = it - Data; return (int)off; }
};
IM_MSVC_RUNTIME_CHECKS_RESTORE
//-----------------------------------------------------------------------------
// [SECTION] ImGuiStyle