From 9750f7690c1aa1fc20dbc0554edc643eade67d57 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 5 Jun 2025 14:10:30 +0100 Subject: [PATCH] Performance optimizations. --- .../3d_viewer/eda_3d_viewer_settings.cpp | 4 +-- common/string_utils.cpp | 2 +- eeschema/sch_io/ltspice/ltspice_schematic.cpp | 2 +- kicad/project_template.cpp | 2 +- libs/kimath/src/geometry/shape_poly_set.cpp | 22 ++++++------ pcbnew/board.cpp | 2 +- pcbnew/connectivity/connectivity_algo.cpp | 2 +- pcbnew/connectivity/from_to_cache.cpp | 16 ++++----- pcbnew/dialogs/dialog_board_reannotate.cpp | 10 +++--- pcbnew/drc/drc_creepage_utils.cpp | 36 +++++++++---------- pcbnew/footprint.cpp | 2 +- pcbnew/pcbexpr_evaluator.h | 2 +- pcbnew/teardrop/teardrop_utils.cpp | 2 +- 13 files changed, 53 insertions(+), 51 deletions(-) diff --git a/3d-viewer/3d_viewer/eda_3d_viewer_settings.cpp b/3d-viewer/3d_viewer/eda_3d_viewer_settings.cpp index d292a4a52c..433c4a144b 100644 --- a/3d-viewer/3d_viewer/eda_3d_viewer_settings.cpp +++ b/3d-viewer/3d_viewer/eda_3d_viewer_settings.cpp @@ -329,7 +329,7 @@ EDA_3D_VIEWER_SETTINGS::EDA_3D_VIEWER_SETTINGS() : m_params.emplace_back( new PARAM_LIST( "render.raytrace_lightElevation", &m_Render.raytrace_lightElevation, - default_elevation ) ); + std::move( default_elevation ) ) ); const std::vector default_azimuth = { @@ -338,7 +338,7 @@ EDA_3D_VIEWER_SETTINGS::EDA_3D_VIEWER_SETTINGS() : m_params.emplace_back( new PARAM_LIST( "render.raytrace_lightAzimuth", &m_Render.raytrace_lightAzimuth, - default_azimuth ) ); + std::move( default_azimuth ) ) ); m_params.emplace_back( new PARAM( "render.show_adhesive", &m_Render.show_adhesive, true ) ); diff --git a/common/string_utils.cpp b/common/string_utils.cpp index 5348d055af..ece42491a8 100644 --- a/common/string_utils.cpp +++ b/common/string_utils.cpp @@ -1342,7 +1342,7 @@ bool ReplaceIllegalFileNameChars( wxString& aName, int aReplaceChar ) } if( changed ) - aName = result; + aName = std::move( result ); return changed; } diff --git a/eeschema/sch_io/ltspice/ltspice_schematic.cpp b/eeschema/sch_io/ltspice/ltspice_schematic.cpp index 0b02c64222..a8674d72af 100644 --- a/eeschema/sch_io/ltspice/ltspice_schematic.cpp +++ b/eeschema/sch_io/ltspice/ltspice_schematic.cpp @@ -1178,7 +1178,7 @@ std::vector LTSPICE_SCHEMATIC::StructureBuilder() lineNumber++; } - ascFiles.push_back( ascFile ); + ascFiles.push_back( std::move( ascFile ) ); } return ascFiles; diff --git a/kicad/project_template.cpp b/kicad/project_template.cpp index b097a60a59..93bcff1988 100644 --- a/kicad/project_template.cpp +++ b/kicad/project_template.cpp @@ -74,7 +74,7 @@ PROJECT_TEMPLATE::PROJECT_TEMPLATE( const wxString& aPath ) class FILE_TRAVERSER : public wxDirTraverser { public: - FILE_TRAVERSER( std::vector& files, const wxString exclude ) : + FILE_TRAVERSER( std::vector& files, const wxString& exclude ) : m_files( files ), m_exclude( exclude ) { } diff --git a/libs/kimath/src/geometry/shape_poly_set.cpp b/libs/kimath/src/geometry/shape_poly_set.cpp index ced9a8e274..da7d6b54db 100644 --- a/libs/kimath/src/geometry/shape_poly_set.cpp +++ b/libs/kimath/src/geometry/shape_poly_set.cpp @@ -556,9 +556,9 @@ int SHAPE_POLY_SET::AddOutline( const SHAPE_LINE_CHAIN& aOutline ) wxCHECK2_MSG( aOutline.IsClosed(), poly.back().SetClosed( true ), "Warning: non-closed outline added to SHAPE_POLY_SET" ); - m_polys.push_back( poly ); + m_polys.push_back( std::move( poly ) ); - return m_polys.size() - 1; + return (int) m_polys.size() - 1; } @@ -567,7 +567,7 @@ int SHAPE_POLY_SET::AddHole( const SHAPE_LINE_CHAIN& aHole, int aOutline ) assert( m_polys.size() ); if( aOutline < 0 ) - aOutline += m_polys.size(); + aOutline += (int) m_polys.size(); assert( aOutline < (int)m_polys.size() ); @@ -577,7 +577,7 @@ int SHAPE_POLY_SET::AddHole( const SHAPE_LINE_CHAIN& aHole, int aOutline ) poly.push_back( aHole ); - return poly.size() - 2; + return (int) poly.size() - 2; } @@ -741,7 +741,7 @@ void SHAPE_POLY_SET::RebuildHolesFromContours() for( int topParentId : topLevelParents ) { std::vector path; - process( topParentId, -1, path ); + process( topParentId, -1, std::move( path ) ); } *this = result; @@ -1156,7 +1156,7 @@ void SHAPE_POLY_SET::importPolyPath( const std::unique_ptr 0 ) std::swap( result[0], result[outline] ); - aPoly = result; + aPoly = std::move( result ); } @@ -1994,7 +1996,7 @@ bool SHAPE_POLY_SET::Parse( std::stringstream& aStream ) outline.Append( p ); } - paths.push_back( outline ); + paths.push_back( std::move( outline ) ); } m_polys.push_back( paths ); diff --git a/pcbnew/board.cpp b/pcbnew/board.cpp index 56de079ba6..4ab54c035f 100644 --- a/pcbnew/board.cpp +++ b/pcbnew/board.cpp @@ -1463,7 +1463,7 @@ void BOARD::DeleteMARKERs( bool aWarningsAndErrors, bool aExclusions ) } } - m_markers = remaining; + m_markers = std::move( remaining ); } diff --git a/pcbnew/connectivity/connectivity_algo.cpp b/pcbnew/connectivity/connectivity_algo.cpp index 3c91a8a78d..e99ea29834 100644 --- a/pcbnew/connectivity/connectivity_algo.cpp +++ b/pcbnew/connectivity/connectivity_algo.cpp @@ -400,7 +400,7 @@ CN_CONNECTIVITY_ALGO::SearchClusters( CLUSTER_SEARCH_MODE aMode, bool aExcludeZo } } - clusters.push_back( cluster ); + clusters.push_back( std::move( cluster ) ); } if( m_progressReporter && m_progressReporter->IsCancelled() ) diff --git a/pcbnew/connectivity/from_to_cache.cpp b/pcbnew/connectivity/from_to_cache.cpp index be66d941d6..86f29f3d48 100644 --- a/pcbnew/connectivity/from_to_cache.cpp +++ b/pcbnew/connectivity/from_to_cache.cpp @@ -44,7 +44,7 @@ void FROM_TO_CACHE::buildEndpointList( ) m_ftEndpoints.push_back( ent ); ent.name = footprint->GetReference(); ent.parent = pad; - m_ftEndpoints.push_back( ent ); + m_ftEndpoints.push_back( std::move( ent ) ); } } } @@ -77,7 +77,7 @@ static PATH_STATUS uniquePathBetweenNodes( CN_ITEM* u, CN_ITEM* v, std::vector& p : Q ) + { if( isVertexVisited( ci, p ) ) { vertexVisited = true; break; } + } if( !vertexVisited ) { Path newpath( path ); newpath.push_back( ci ); - Q.push_back( newpath ); + Q.push_back( std::move( newpath ) ); } } } @@ -133,7 +135,7 @@ int FROM_TO_CACHE::cacheFromToPaths( const wxString& aFrom, const wxString& aTo p.net = endpoint.parent->GetNetCode(); p.from = endpoint.parent; p.to = nullptr; - paths.push_back(p); + paths.push_back( std::move( p ) ); } } @@ -207,12 +209,10 @@ int FROM_TO_CACHE::cacheFromToPaths( const wxString& aFrom, const wxString& aTo if( result == PS_NO_PATH ) continue; - for( const auto item : upath ) - { + for( const CN_ITEM* item : upath ) path.pathItems.insert( item->Parent() ); - } - m_ftPaths.push_back(path); + m_ftPaths.push_back( path ); newPaths++; } diff --git a/pcbnew/dialogs/dialog_board_reannotate.cpp b/pcbnew/dialogs/dialog_board_reannotate.cpp index 062102eba7..f5e2fd914e 100644 --- a/pcbnew/dialogs/dialog_board_reannotate.cpp +++ b/pcbnew/dialogs/dialog_board_reannotate.cpp @@ -722,7 +722,7 @@ bool DIALOG_BOARD_REANNOTATE::BuildFootprintList( std::vector& aBad // Get the type (R, C, etc) fpData.RefDesType = fpData.RefDesString.substr( 0, firstnum ); - for( wxString excluded : m_excludeArray ) + for( const wxString& excluded : m_excludeArray ) { if( excluded == fpData.RefDesType ) // Am I supposed to exclude this type? { @@ -742,7 +742,7 @@ bool DIALOG_BOARD_REANNOTATE::BuildFootprintList( std::vector& aBad { // If only annotating selected c fpData.Action = EXCLUDE_REFDES; // Assume it isn't selected - for( KIID sel : selected ) + for( const KIID& sel : selected ) { if( fpData.Uuid == sel ) { // Found in selected footprints @@ -827,19 +827,19 @@ void DIALOG_BOARD_REANNOTATE::BuildUnavailableRefsList() { std::vector excludedFootprints; - for( REFDES_INFO fpData : m_frontFootprints ) + for( const REFDES_INFO& fpData : m_frontFootprints ) { if( fpData.Action == EXCLUDE_REFDES ) excludedFootprints.push_back( fpData ); } - for( REFDES_INFO fpData : m_backFootprints ) + for( const REFDES_INFO& fpData : m_backFootprints ) { if( fpData.Action == EXCLUDE_REFDES ) excludedFootprints.push_back( fpData ); } - for( REFDES_INFO fpData : excludedFootprints ) + for( const REFDES_INFO& fpData : excludedFootprints ) { if( fpData.Action == EXCLUDE_REFDES ) { diff --git a/pcbnew/drc/drc_creepage_utils.cpp b/pcbnew/drc/drc_creepage_utils.cpp index dd73207083..1b36d42573 100644 --- a/pcbnew/drc/drc_creepage_utils.cpp +++ b/pcbnew/drc/drc_creepage_utils.cpp @@ -1716,14 +1716,12 @@ std::vector CU_SHAPE_ARC::Paths( const CU_SHAPE_ARC& aS2, doubl } } - for( std::vector pcs : { pcs3, pcs4, pcs5, pcs6 } ) + for( const std::vector& pcs : { pcs3, pcs4, pcs5, pcs6 } ) { - for( PATH_CONNECTION& pc : pcs ) + for( const PATH_CONNECTION& pc : pcs ) { if( bestPath.weight > pc.weight ) - { bestPath = pc; - } } } @@ -1781,13 +1779,15 @@ bool SegmentIntersectsBoard( const VECTOR2I& aP1, const VECTOR2I& aP2, { case SHAPE_T::SEGMENT: { - bool intersects = - segments_intersect( aP1, aP2, d->GetStart(), d->GetEnd(), &intersectionPoints ); + bool intersects = segments_intersect( aP1, aP2, d->GetStart(), d->GetEnd(), + &intersectionPoints ); if( intersects && !TestGrooveWidth ) return false; + break; } + case SHAPE_T::RECTANGLE: { VECTOR2I c1 = d->GetStart(); @@ -1802,11 +1802,11 @@ bool SegmentIntersectsBoard( const VECTOR2I& aP1, const VECTOR2I& aP2, intersects |= segments_intersect( aP1, aP2, c4, c1, &intersectionPoints ); if( intersects && !TestGrooveWidth ) - { return false; - } + break; } + case SHAPE_T::POLY: { std::vector points; @@ -1814,28 +1814,29 @@ bool SegmentIntersectsBoard( const VECTOR2I& aP1, const VECTOR2I& aP2, if( points.size() < 2 ) break; + VECTOR2I prevPoint = points.back(); bool intersects = false; - for( auto p : points ) + for( const VECTOR2I& p : points ) { intersects |= segments_intersect( aP1, aP2, prevPoint, p, &intersectionPoints ); prevPoint = p; } + if( intersects && !TestGrooveWidth ) - { return false; - } + break; } + case SHAPE_T::CIRCLE: { VECTOR2I center = d->GetCenter(); double radius = d->GetRadius(); - bool intersects = - segmentIntersectsCircle( aP1, aP2, center, radius, &intersectionPoints ); + bool intersects = segmentIntersectsCircle( aP1, aP2, center, radius, &intersectionPoints ); if( intersects && !TestGrooveWidth ) return false; @@ -1843,7 +1844,6 @@ bool SegmentIntersectsBoard( const VECTOR2I& aP1, const VECTOR2I& aP2, break; } - case SHAPE_T::ARC: { VECTOR2I center = d->GetCenter(); @@ -1852,8 +1852,7 @@ bool SegmentIntersectsBoard( const VECTOR2I& aP1, const VECTOR2I& aP2, EDA_ANGLE A, B; d->CalcArcAngles( A, B ); - bool intersects = - segmentIntersectsArc( aP1, aP2, center, radius, A, B, &intersectionPoints ); + bool intersects = segmentIntersectsArc( aP1, aP2, center, radius, A, B, &intersectionPoints ); if( intersects && !TestGrooveWidth ) return false; @@ -1906,19 +1905,20 @@ bool SegmentIntersectsBoard( const VECTOR2I& aP1, const VECTOR2I& aP2, for( size_t i = 0; i < intersectionPoints.size(); i += 2 ) { if( intersectionPoints[i].SquaredDistance( intersectionPoints[i + 1] ) > GVSquared ) - { return false; - } } + return true; } + bool CheckPathValidity( VECTOR2I aP1, VECTOR2I aP2, std::vector aBe, std::vector aDontTestAgainst ) { return false; } + std::vector GetPaths( CREEP_SHAPE* aS1, CREEP_SHAPE* aS2, double aMaxWeight ) { double maxWeight = aMaxWeight; diff --git a/pcbnew/footprint.cpp b/pcbnew/footprint.cpp index 416decf5c7..2b5776b1f0 100644 --- a/pcbnew/footprint.cpp +++ b/pcbnew/footprint.cpp @@ -564,7 +564,7 @@ bool FOOTPRINT::Deserialize( const google::protobuf::Any &aContainer ) model.m_Rotation = kiapi::common::UnpackVector3D( modelMsg.rotation() ); model.m_Offset = kiapi::common::UnpackVector3D( modelMsg.offset() ); - Models().push_back( model ); + Models().push_back( std::move( model ) ); } else { diff --git a/pcbnew/pcbexpr_evaluator.h b/pcbnew/pcbexpr_evaluator.h index 53a42a895f..77f0fb6520 100644 --- a/pcbnew/pcbexpr_evaluator.h +++ b/pcbnew/pcbexpr_evaluator.h @@ -250,7 +250,7 @@ public: void SetErrorCallback( std::function aCallback ) { - m_compiler.SetErrorCallback( aCallback ); + m_compiler.SetErrorCallback( std::move( aCallback ) ); } bool IsErrorPending() const { return m_errorStatus.pendingError; } diff --git a/pcbnew/teardrop/teardrop_utils.cpp b/pcbnew/teardrop/teardrop_utils.cpp index 0ef00f440c..92bdb0ff4f 100644 --- a/pcbnew/teardrop/teardrop_utils.cpp +++ b/pcbnew/teardrop/teardrop_utils.cpp @@ -745,7 +745,7 @@ bool TEARDROP_MANAGER::computeTeardropPolygon( const TEARDROP_PARAMETERS& aParam if( !aParams.m_CurvedEdges ) { - aCorners = pts; + aCorners = std::move( pts ); return true; }