From 32810e4e9a4c9b9ef7d6dbda733a32877b74524e Mon Sep 17 00:00:00 2001 From: Tristan Walter <twalter@orn.mpg.de> Date: Thu, 5 Nov 2020 15:21:28 +0100 Subject: [PATCH] * dont perform narrow_cast checks in release mode --- Application/src/commons/common/gui/IMGUIBase.cpp | 6 +++--- Application/src/commons/common/misc/metastring.h | 13 ++++++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Application/src/commons/common/gui/IMGUIBase.cpp b/Application/src/commons/common/gui/IMGUIBase.cpp index ac869f5..3cff68e 100644 --- a/Application/src/commons/common/gui/IMGUIBase.cpp +++ b/Application/src/commons/common/gui/IMGUIBase.cpp @@ -851,8 +851,8 @@ void PolyFillScanFlood(ImDrawList *draw, std::vector<ImVec2> *poly, ImColor colo ImVec2 fp = poly->at(0); for (size_t i = 0; i < polysize - 1; i++) { - ImVec2 pa = poly->at(i); - ImVec2 pb = poly->at(i+1); + ImVec2 pa = (*poly)[i]; + ImVec2 pb = (*poly)[i+1]; // jump double/dud points if (pa.x == pb.x && pa.y == pb.y) continue; @@ -862,7 +862,7 @@ void PolyFillScanFlood(ImDrawList *draw, std::vector<ImVec2> *poly, ImColor colo // hull, jump the next segment and reset the first-point if ((!jump) && (fp.x == pb.x) && (fp.y == pb.y)) { if (i < polysize - 2) { - fp = poly->at(i + 2); + fp = (*poly)[i + 2]; jump = 1; i++; } diff --git a/Application/src/commons/common/misc/metastring.h b/Application/src/commons/common/misc/metastring.h index 40f57d0..7eaaa5c 100644 --- a/Application/src/commons/common/misc/metastring.h +++ b/Application/src/commons/common/misc/metastring.h @@ -1077,6 +1077,7 @@ void fail_type(From&& value) { template<typename To, typename From> constexpr To sign_cast(From&& value) { +#ifndef NDEBUG using FromType = typename remove_cvref<From>::type; using ToType = typename remove_cvref<To>::type; @@ -1096,12 +1097,13 @@ constexpr To sign_cast(From&& value) { fail_type<To, From>(std::forward<From>(value)); } } - +#endif return static_cast<To>(std::forward<From>(value)); } template<typename To, typename From> constexpr bool check_narrow_cast(const From& value) { +#ifndef NDEBUG using FromType = typename remove_cvref<From>::type; using ToType = typename remove_cvref<To>::type; @@ -1165,10 +1167,14 @@ constexpr bool check_narrow_cast(const From& value) { #endif return value >= 0 && static_cast<unsigned_t>(value) <= static_cast<unsigned_t>(std::numeric_limits<To>::max()); } +#else + return true; +#endif } template<typename To, typename From> constexpr To narrow_cast(From&& value, struct tag::warn_on_error) { +#ifndef NDEBUG if (!check_narrow_cast<To, From>(value)) { auto vstr = Meta::toStr(value); auto lstr = Meta::toStr(std::numeric_limits<To>::min()); @@ -1178,12 +1184,13 @@ constexpr To narrow_cast(From&& value, struct tag::warn_on_error) { auto fstr = Meta::name<From>(); Warning("Value '%S' in narrowing conversion of %S -> %S is not within limits [%S,%S].", &vstr, &fstr, &tstr, &lstr, &rstr); } - +#endif return static_cast<To>(std::forward<From>(value)); } template<typename To, typename From> constexpr To narrow_cast(From&& value, struct tag::fail_on_error) { +#ifndef NDEBUG if (!check_narrow_cast<To, From>(value)) { auto vstr = Meta::toStr(value); auto lstr = Meta::toStr(std::numeric_limits<To>::min()); @@ -1193,7 +1200,7 @@ constexpr To narrow_cast(From&& value, struct tag::fail_on_error) { auto fstr = Meta::name<From>(); U_EXCEPTION("Value '%S' in narrowing conversion of %S -> %S is not within limits [%S,%S].", &vstr, &fstr, &tstr, &lstr, &rstr); } - +#endif return static_cast<To>(std::forward<From>(value)); } -- GitLab