Browse Source

Fix slightly over-zealous optimisation.

(Also prunes double-matching against plainNumber regex.)
jobs
Jeff Young 1 year ago
parent
commit
8178469182
  1. 26
      eeschema/sim/sim_model.cpp
  2. 20
      eeschema/sim/sim_value.cpp
  3. 5
      eeschema/sim/sim_value.h

26
eeschema/sim/sim_model.cpp

@ -838,20 +838,22 @@ void SIM_MODEL::SetParamValue( int aParamIndex, const std::string& aValue,
{
static const wxRegEx plainNumber( wxS( "^[0-9.]*$" ) );
// PEGTL is slow as shit. Avoid if possible.
if( aNotation != SIM_VALUE::NOTATION::SI )
{
wxString value( aValue );
// Notation conversion is very slow. Avoid if possible.
if( !plainNumber.Matches( value ) )
{
doSetParamValue( aParamIndex, SIM_VALUE::ConvertNotation( aValue, aNotation,
SIM_VALUE::NOTATION::SI ) );
return;
}
if( aValue.find( ',' ) != std::string::npos )
{
doSetParamValue( aParamIndex, SIM_VALUE::ConvertNotation( aValue, aNotation,
SIM_VALUE::NOTATION::SI ) );
}
else if( aNotation != SIM_VALUE::NOTATION::SI && !plainNumber.Matches( wxString( aValue ) ) )
{
doSetParamValue( aParamIndex, SIM_VALUE::ConvertNotation( aValue, aNotation,
SIM_VALUE::NOTATION::SI ) );
}
else
{
doSetParamValue( aParamIndex, aValue );
}
doSetParamValue( aParamIndex, aValue );
}

20
eeschema/sim/sim_value.cpp

@ -371,13 +371,6 @@ std::string SIM_VALUE::ConvertNotation( const std::string& aString, NOTATION aFr
NOTATION aToNotation )
{
wxString buf( aString );
// PEGTL is slow as shit. Avoid if possible.
static const wxRegEx plainNumber( wxS( "^[0-9.]*$" ) );
if( plainNumber.Matches( buf ) )
return aString;
buf.Replace( ',', '.' );
SIM_VALUE_PARSER::PARSE_RESULT parseResult = SIM_VALUE_PARSER::Parse( buf.ToStdString(),
@ -423,6 +416,19 @@ std::string SIM_VALUE::Normalize( double aValue )
}
std::string SIM_VALUE::ToSpice( const std::string& aString )
{
static const wxRegEx plainNumber( wxS( "^[0-9.]*$" ) );
// Notation conversion is very slow. Avoid if possible.
if( plainNumber.Matches( wxString( aString ) ) )
return aString;
else
return ConvertNotation( aString, NOTATION::SI, NOTATION::SPICE );
}
double SIM_VALUE::ToDouble( const std::string& aString, double aDefault )
{
SIM_VALUE_PARSER::PARSE_RESULT parseResult = SIM_VALUE_PARSER::Parse( aString, NOTATION::SI );

5
eeschema/sim/sim_value.h

@ -81,10 +81,7 @@ public:
static std::string Normalize( double aValue );
static std::string ToSpice( const std::string& aString )
{
return ConvertNotation( aString, NOTATION::SI, NOTATION::SPICE );
}
static std::string ToSpice( const std::string& aString );
static double ToDouble( const std::string& aString, double aDefault = NAN );

Loading…
Cancel
Save