From 50d3a507d044a91a59a17ffadd5c750ac17c495a Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Fri, 4 Feb 2022 07:48:14 -0500 Subject: [PATCH] Mark some limits as constexpr gcc doesn't need it and computes during compile regardless, but experimenting in godbolt, both clang and MSVC actually do need it or else it's partially computed at runtime (cherry picked from commit ca7840334cfa1856f5cf5a66b38fadd6e9616744) --- common/plugins/altium/altium_parser.cpp | 2 +- eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp | 4 ++-- pcbnew/plugins/kicad/pcb_parser.cpp | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/common/plugins/altium/altium_parser.cpp b/common/plugins/altium/altium_parser.cpp index 5f9f412e77..2b61bb999e 100644 --- a/common/plugins/altium/altium_parser.cpp +++ b/common/plugins/altium/altium_parser.cpp @@ -176,7 +176,7 @@ std::map ALTIUM_PARSER::ReadProperties() int32_t ALTIUM_PARSER::ConvertToKicadUnit( const double aValue ) { - const double int_limit = ( std::numeric_limits::max() - 1 ) / 2.54; + constexpr double int_limit = ( std::numeric_limits::max() - 1 ) / 2.54; int32_t iu = KiROUND( Clamp( -int_limit, aValue, int_limit ) * 2.54 ); diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp index fbe9d4ad8f..469f8fe0dc 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp @@ -448,7 +448,7 @@ int SCH_SEXPR_PARSER::parseInternalUnits() // Schematic internal units are represented as integers. Any values that are // larger or smaller than the schematic units represent undefined behavior for // the system. Limit values to the largest that can be displayed on the screen. - double int_limit = std::numeric_limits::max() * 0.7071; // 0.7071 = roughly 1/sqrt(2) + constexpr double int_limit = std::numeric_limits::max() * 0.7071; // 0.7071 = roughly 1/sqrt(2) return KiROUND( Clamp( -int_limit, retval, int_limit ) ); } @@ -458,7 +458,7 @@ int SCH_SEXPR_PARSER::parseInternalUnits( const char* aExpected ) { auto retval = parseDouble( aExpected ) * IU_PER_MM; - double int_limit = std::numeric_limits::max() * 0.7071; + constexpr double int_limit = std::numeric_limits::max() * 0.7071; return KiROUND( Clamp( -int_limit, retval, int_limit ) ); } diff --git a/pcbnew/plugins/kicad/pcb_parser.cpp b/pcbnew/plugins/kicad/pcb_parser.cpp index 38e86bb3ed..eb08c2e502 100644 --- a/pcbnew/plugins/kicad/pcb_parser.cpp +++ b/pcbnew/plugins/kicad/pcb_parser.cpp @@ -208,7 +208,8 @@ int PCB_PARSER::parseBoardUnits() // larger or smaller than those board units represent undefined behavior for // the system. We limit values to the largest that is visible on the screen // This is the diagonal distance of the full screen ~1.5m - double int_limit = std::numeric_limits::max() * 0.7071; // 0.7071 = roughly 1/sqrt(2) + constexpr double int_limit = + std::numeric_limits::max() * 0.7071; // 0.7071 = roughly 1/sqrt(2) return KiROUND( Clamp( -int_limit, retval, int_limit ) ); } @@ -220,7 +221,7 @@ int PCB_PARSER::parseBoardUnits( const char* aExpected ) // N.B. we currently represent board units as integers. Any values that are // larger or smaller than those board units represent undefined behavior for // the system. We limit values to the largest that is visible on the screen - double int_limit = std::numeric_limits::max() * 0.7071; + constexpr double int_limit = std::numeric_limits::max() * 0.7071; // Use here #KiROUND, not EKIROUND (see comments about them) when having a function as // argument, because it will be called twice with #KIROUND.