From ca7840334cfa1856f5cf5a66b38fadd6e9616744 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 --- 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 80551cf1c3..13cb1dbe46 100644 --- a/common/plugins/altium/altium_parser.cpp +++ b/common/plugins/altium/altium_parser.cpp @@ -242,7 +242,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 2a931d1101..7f9ab3afb4 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp @@ -458,7 +458,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 ) ); } @@ -468,7 +468,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 57c9dc1213..dd5e400c3e 100644 --- a/pcbnew/plugins/kicad/pcb_parser.cpp +++ b/pcbnew/plugins/kicad/pcb_parser.cpp @@ -210,7 +210,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 ) ); } @@ -222,7 +223,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.