From e6346e31032ced2e05ec76befb086c89c39d109b Mon Sep 17 00:00:00 2001
From: Wayne Stambaugh <stambaughw@gmail.com>
Date: Tue, 8 Jun 2021 13:47:06 -0400
Subject: [PATCH] Pass objects by reference instead of on the stack part 2.

---
 common/drawing_sheet/ds_data_item.cpp     | 36 +++-------------
 common/drawing_sheet/ds_data_model_io.cpp | 51 +++++++++++------------
 common/project/net_settings.cpp           | 42 +++++++++++++------
 common/project/project_local_settings.cpp |  5 ++-
 common/view/view.cpp                      | 47 +++++++++++----------
 common/view/view_overlay.cpp              |  5 ++-
 include/drawing_sheet/ds_data_item.h      | 37 ++++++++--------
 include/drawing_sheet/ds_data_model.h     |  8 ++--
 include/drawing_sheet/ds_draw_item.h      | 20 ++++-----
 include/project/board_project_settings.h  | 12 +++---
 include/project/net_settings.h            | 14 ++++---
 include/project/project_file.h            | 22 +++++-----
 include/project/project_local_settings.h  | 21 +++++-----
 include/view/view.h                       |  2 +-
 include/view/view_overlay.h               |  8 ++--
 pcbnew/connectivity/connectivity_items.h  |  8 ++--
 16 files changed, 163 insertions(+), 175 deletions(-)

diff --git a/common/drawing_sheet/ds_data_item.cpp b/common/drawing_sheet/ds_data_item.cpp
index 40cea27e24..6cb04d6817 100644
--- a/common/drawing_sheet/ds_data_item.cpp
+++ b/common/drawing_sheet/ds_data_item.cpp
@@ -62,7 +62,6 @@
 using KIGFX::COLOR4D;
 
 
-// The constructor:
 DS_DATA_ITEM::DS_DATA_ITEM( DS_ITEM_TYPE aType )
 {
     m_pageOption = ALL_PAGES;
@@ -144,13 +143,7 @@ int DS_DATA_ITEM::GetPenSizeUi()
 }
 
 
-// move item to aPosition
-// starting point is moved to aPosition
-// the Ending point is moved to a position which keeps the item size
-// (if both coordinates have the same corner reference)
-// MoveToUi and MoveTo takes the graphic position (i.e relative to the left top
-// paper corner
-void DS_DATA_ITEM::MoveToUi( wxPoint aPosition )
+void DS_DATA_ITEM::MoveToUi( const wxPoint& aPosition )
 {
     DPOINT pos_mm;
     pos_mm.x = aPosition.x / DS_DATA_MODEL::GetTheInstance().m_WSunits2Iu;
@@ -160,7 +153,7 @@ void DS_DATA_ITEM::MoveToUi( wxPoint aPosition )
 }
 
 
-void DS_DATA_ITEM::MoveTo( DPOINT aPosition )
+void DS_DATA_ITEM::MoveTo( const DPOINT& aPosition )
 {
     DPOINT vector = aPosition - GetStartPos();
     DPOINT endpos = vector + GetEndPos();
@@ -176,10 +169,7 @@ void DS_DATA_ITEM::MoveTo( DPOINT aPosition )
 }
 
 
-/* move the starting point of the item to a new position
- * aPosition = the new position of the starting point, in mm
- */
-void DS_DATA_ITEM::MoveStartPointTo( DPOINT aPosition )
+void DS_DATA_ITEM::MoveStartPointTo( const DPOINT& aPosition )
 {
     DS_DATA_MODEL& model = DS_DATA_MODEL::GetTheInstance();
     DPOINT         position;
@@ -212,10 +202,7 @@ void DS_DATA_ITEM::MoveStartPointTo( DPOINT aPosition )
 }
 
 
-/* move the starting point of the item to a new position
- * aPosition = the new position of the starting point in graphic units
- */
-void DS_DATA_ITEM::MoveStartPointToUi( wxPoint aPosition )
+void DS_DATA_ITEM::MoveStartPointToUi( const wxPoint& aPosition )
 {
     DPOINT pos_mm( aPosition.x / DS_DATA_MODEL::GetTheInstance().m_WSunits2Iu,
                    aPosition.y / DS_DATA_MODEL::GetTheInstance().m_WSunits2Iu );
@@ -224,13 +211,7 @@ void DS_DATA_ITEM::MoveStartPointToUi( wxPoint aPosition )
 }
 
 
-/**
- * move the ending point of the item to a new position
- * has meaning only for items defined by 2 points
- * (segments and rectangles)
- * aPosition = the new position of the ending point, in mm
- */
-void DS_DATA_ITEM::MoveEndPointTo( DPOINT aPosition )
+void DS_DATA_ITEM::MoveEndPointTo( const DPOINT& aPosition )
 {
     DS_DATA_MODEL& model = DS_DATA_MODEL::GetTheInstance();
     DPOINT         position;
@@ -273,12 +254,7 @@ void DS_DATA_ITEM::MoveEndPointTo( DPOINT aPosition )
 }
 
 
-/* move the ending point of the item to a new position
- * has meaning only for items defined by 2 points
- * (segments and rectangles)
- * aPosition = the new position of the ending point in graphic units
- */
-void DS_DATA_ITEM::MoveEndPointToUi( wxPoint aPosition )
+void DS_DATA_ITEM::MoveEndPointToUi( const wxPoint& aPosition )
 {
     DPOINT pos_mm;
     pos_mm.x = aPosition.x / DS_DATA_MODEL::GetTheInstance().m_WSunits2Iu;
diff --git a/common/drawing_sheet/ds_data_model_io.cpp b/common/drawing_sheet/ds_data_model_io.cpp
index 69883998a4..fcb672b123 100644
--- a/common/drawing_sheet/ds_data_model_io.cpp
+++ b/common/drawing_sheet/ds_data_model_io.cpp
@@ -2,7 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2013-2016 CERN
- * Copyright (C) 2019 Kicad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * @author Jean-Pierre Charras, jp.charras at wanadoo.fr
  *
@@ -51,34 +51,32 @@ static const char* getTokenName( T aTok )
 // Therefore the constructor is protected.
 class DS_DATA_MODEL_IO
 {
-protected:
-    OUTPUTFORMATTER* m_out;
-
-    DS_DATA_MODEL_IO() { m_out = NULL; }
-    virtual ~DS_DATA_MODEL_IO() {}
-
 public:
     void Format( DS_DATA_MODEL* aDrawingSheet ) const;
 
     void Format( DS_DATA_MODEL* aModel, DS_DATA_ITEM* aItem, int aNestLevel ) const;
 
+protected:
+    DS_DATA_MODEL_IO() { m_out = NULL; }
+    virtual ~DS_DATA_MODEL_IO() {}
+
 private:
     void format( DS_DATA_ITEM_TEXT* aItem, int aNestLevel ) const;
     void format( DS_DATA_MODEL* aModel, DS_DATA_ITEM* aItem, int aNestLevel ) const;
-    void format( DS_DATA_ITEM_POLYGONS* aItem, int aNestLevel )
-                 const;
+    void format( DS_DATA_ITEM_POLYGONS* aItem, int aNestLevel ) const;
     void format( DS_DATA_ITEM_BITMAP* aItem, int aNestLevel ) const;
-    void formatCoordinate( const char * aToken, POINT_COORD & aCoord ) const;
+    void formatCoordinate( const char* aToken, POINT_COORD& aCoord ) const;
     void formatRepeatParameters( DS_DATA_ITEM* aItem ) const;
     void formatOptions( DS_DATA_ITEM* aItem ) const;
+
+protected:
+    OUTPUTFORMATTER* m_out;
 };
 
 
 // A helper class to write a drawing sheet to a file
 class DS_DATA_MODEL_FILEIO : public DS_DATA_MODEL_IO
 {
-    FILE_OUTPUTFORMATTER * m_fileout;
-
 public:
     DS_DATA_MODEL_FILEIO( const wxString& aFilename ) :
             DS_DATA_MODEL_IO()
@@ -98,18 +96,19 @@ public:
     {
         delete m_fileout;
     }
+
+private:
+    FILE_OUTPUTFORMATTER* m_fileout;
 };
 
 
 // A helper class to write a drawing sheet to a string
 class DS_DATA_MODEL_STRINGIO : public DS_DATA_MODEL_IO
 {
-    STRING_FORMATTER * m_writer;
-    wxString & m_output;
-
 public:
-    DS_DATA_MODEL_STRINGIO( wxString& aOutputString ) :
-            DS_DATA_MODEL_IO(), m_output( aOutputString )
+    DS_DATA_MODEL_STRINGIO( const wxString& aOutputString ) :
+            DS_DATA_MODEL_IO(),
+            m_output( aOutputString )
     {
         try
         {
@@ -127,12 +126,13 @@ public:
         m_output = FROM_UTF8( m_writer->GetString().c_str() );
         delete m_writer;
     }
+
+private:
+    STRING_FORMATTER* m_writer;
+    wxString m_output;
 };
 
 
-/*
- * Save the description in a file
- */
 void DS_DATA_MODEL::Save( const wxString& aFullFileName )
 {
     DS_DATA_MODEL_FILEIO writer( aFullFileName );
@@ -140,16 +140,15 @@ void DS_DATA_MODEL::Save( const wxString& aFullFileName )
 }
 
 
-/* Save the description in a buffer
- */
-void DS_DATA_MODEL::SaveInString( wxString& aOutputString )
+void DS_DATA_MODEL::SaveInString( const wxString& aOutputString )
 {
     DS_DATA_MODEL_STRINGIO writer( aOutputString );
     writer.Format( this );
 }
 
 
-void DS_DATA_MODEL::SaveInString( std::vector<DS_DATA_ITEM*> aItemsList, wxString& aOutputString )
+void DS_DATA_MODEL::SaveInString( std::vector<DS_DATA_ITEM*>& aItemsList,
+                                  const wxString& aOutputString )
 {
     DS_DATA_MODEL_STRINGIO writer( aOutputString );
 
@@ -311,6 +310,7 @@ void DS_DATA_MODEL_IO::format( DS_DATA_ITEM_TEXT* aItem, int aNestLevel ) const
     m_out->Print( 0, ")\n" );
 }
 
+
 void DS_DATA_MODEL_IO::format( DS_DATA_MODEL* aModel, DS_DATA_ITEM* aItem, int aNestLevel ) const
 {
     if( aItem->GetType() == DS_DATA_ITEM::DS_RECT )
@@ -421,8 +421,7 @@ void DS_DATA_MODEL_IO::format( DS_DATA_ITEM_BITMAP* aItem, int aNestLevel ) cons
 }
 
 
-void DS_DATA_MODEL_IO::formatCoordinate( const char * aToken,
-                                         POINT_COORD & aCoord ) const
+void DS_DATA_MODEL_IO::formatCoordinate( const char * aToken, POINT_COORD & aCoord ) const
 {
     m_out->Print( 0, " (%s %s %s", aToken,
                   double2Str( aCoord.m_Pos.x ).c_str(),
diff --git a/common/project/net_settings.cpp b/common/project/net_settings.cpp
index 9d91f08bad..42b6d237c9 100644
--- a/common/project/net_settings.cpp
+++ b/common/project/net_settings.cpp
@@ -2,6 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2020 CERN
+ * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
  * @author Jon Evans <jon@craftyjon.com>
  *
  * This program is free software: you can redistribute it and/or modify it
@@ -26,9 +27,12 @@
 #include <kicad_string.h>
 #include <convert_to_biu.h>
 
+
 const int netSettingsSchemaVersion = 0;
 
-static OPT<int> getInPcbUnits( const nlohmann::json& aObj, const std::string& aKey, OPT<int> aDefault = OPT<int>() )
+
+static OPT<int> getInPcbUnits( const nlohmann::json& aObj, const std::string& aKey,
+                               OPT<int> aDefault = OPT<int>() )
 {
     if( aObj.contains( aKey ) && aObj[aKey].is_number() )
         return PcbMillimeter2iu( aObj[aKey].get<double>() );
@@ -36,6 +40,7 @@ static OPT<int> getInPcbUnits( const nlohmann::json& aObj, const std::string& aK
         return aDefault;
 };
 
+
 NET_SETTINGS::NET_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) :
         NESTED_SETTINGS( "net_settings", netSettingsSchemaVersion, aParent, aPath ),
         m_NetClasses()
@@ -69,31 +74,40 @@ NET_SETTINGS::NET_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) :
 
 
                     if( netclass->HasClearance() )
-                        netclassJson.push_back( { "clearance",         PcbIu2Millimeter( netclass->GetClearance() ) } );
+                        netclassJson.push_back( { "clearance",
+                                PcbIu2Millimeter( netclass->GetClearance() ) } );
 
                     if( netclass->HasTrackWidth() )
-                        netclassJson.push_back( { "track_width",       PcbIu2Millimeter( netclass->GetTrackWidth() ) } );
+                        netclassJson.push_back( { "track_width",
+                                PcbIu2Millimeter( netclass->GetTrackWidth() ) } );
 
                     if( netclass->HasViaDiameter() )
-                        netclassJson.push_back( { "via_diameter",      PcbIu2Millimeter( netclass->GetViaDiameter() ) } );
+                        netclassJson.push_back( { "via_diameter",
+                                PcbIu2Millimeter( netclass->GetViaDiameter() ) } );
 
                     if( netclass->HasViaDrill() )
-                        netclassJson.push_back( { "via_drill",         PcbIu2Millimeter( netclass->GetViaDrill() ) } );
+                        netclassJson.push_back( { "via_drill",
+                                PcbIu2Millimeter( netclass->GetViaDrill() ) } );
 
                     if( netclass->HasuViaDiameter() )
-                        netclassJson.push_back( { "microvia_diameter", PcbIu2Millimeter( netclass->GetuViaDiameter() ) } );
+                        netclassJson.push_back( { "microvia_diameter",
+                                PcbIu2Millimeter( netclass->GetuViaDiameter() ) } );
 
                     if( netclass->HasuViaDrill() )
-                        netclassJson.push_back( { "microvia_drill",    PcbIu2Millimeter( netclass->GetuViaDrill() ) } );
+                        netclassJson.push_back( { "microvia_drill",
+                                PcbIu2Millimeter( netclass->GetuViaDrill() ) } );
 
                     if( netclass->HasDiffPairWidth() )
-                        netclassJson.push_back( { "diff_pair_width",   PcbIu2Millimeter( netclass->GetDiffPairWidth() ) } );
+                        netclassJson.push_back( { "diff_pair_width",
+                                PcbIu2Millimeter( netclass->GetDiffPairWidth() ) } );
 
                     if( netclass->HasDiffPairGap() )
-                        netclassJson.push_back( { "diff_pair_gap",     PcbIu2Millimeter( netclass->GetDiffPairGap() ) } );
+                        netclassJson.push_back( { "diff_pair_gap",
+                                PcbIu2Millimeter( netclass->GetDiffPairGap() ) } );
 
                     if( netclass->HasDiffPairViaGap() )
-                        netclassJson.push_back( { "diff_pair_via_gap", PcbIu2Millimeter( netclass->GetDiffPairViaGap() ) } );
+                        netclassJson.push_back( { "diff_pair_via_gap",
+                                PcbIu2Millimeter( netclass->GetDiffPairViaGap() ) } );
 
                     if( idx > 0 )   // No need to store members of Default netclass
                     {
@@ -188,8 +202,10 @@ NET_SETTINGS::NET_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) :
                     if( entry.contains( "pcb_color" ) && entry["pcb_color"].is_string() )
                         netclass->SetPcbColor( entry["pcb_color"].get<KIGFX::COLOR4D>() );
 
-                    if( entry.contains( "schematic_color" ) && entry["schematic_color"].is_string() )
-                        netclass->SetSchematicColor( entry["schematic_color"].get<KIGFX::COLOR4D>() );
+                    if( entry.contains( "schematic_color" )
+                      && entry["schematic_color"].is_string() )
+                        netclass->SetSchematicColor(
+                                entry["schematic_color"].get<KIGFX::COLOR4D>() );
 
                     if( netclass != defaultClass )
                         m_NetClasses.Add( netclass );
@@ -397,7 +413,7 @@ bool NET_SETTINGS::ParseBusVector( const wxString& aBus, wxString* aName,
 }
 
 
-bool NET_SETTINGS::ParseBusGroup( wxString aGroup, wxString* aName,
+bool NET_SETTINGS::ParseBusGroup( const wxString& aGroup, wxString* aName,
                                   std::vector<wxString>* aMemberList )
 {
     size_t   groupLen = aGroup.length();
diff --git a/common/project/project_local_settings.cpp b/common/project/project_local_settings.cpp
index 095c535f00..c84f4c711c 100644
--- a/common/project/project_local_settings.cpp
+++ b/common/project/project_local_settings.cpp
@@ -2,6 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2020 CERN
+ * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
  * @author Jon Evans <jon@craftyjon.com>
  *
  * This program is free software: you can redistribute it and/or modify it
@@ -30,8 +31,8 @@ PROJECT_LOCAL_SETTINGS::PROJECT_LOCAL_SETTINGS( PROJECT* aProject, const wxStrin
         JSON_SETTINGS( aFilename, SETTINGS_LOC::PROJECT, projectLocalSettingsVersion,
                        /* aCreateIfMissing = */ true, /* aCreateIfDefault = */ false,
                        /* aWriteFile = */ true ),
-        m_project( aProject ),
-        m_SelectionFilter()
+        m_SelectionFilter(),
+        m_project( aProject )
 {
     m_params.emplace_back( new PARAM_LAMBDA<std::string>( "board.visible_layers",
             [&]() -> std::string
diff --git a/common/view/view.cpp b/common/view/view.cpp
index 28d739aefe..f0ffe34d65 100644
--- a/common/view/view.cpp
+++ b/common/view/view.cpp
@@ -88,19 +88,6 @@ private:
         aCount = m_layers.size();
     }
 
-    VIEW*   m_view;             ///< Current dynamic view the item is assigned to.
-    int     m_flags;            ///< Visibility flags
-    int     m_requiredUpdate;   ///< Flag required for updating
-    int     m_drawPriority;     ///< Order to draw this item in a layer, lowest first
-
-    ///< Helper for storing cached items group ids
-    typedef std::pair<int, int> GroupPair;
-
-    ///< Indexes of cached GAL display lists corresponding to the item (for every layer it.
-    ///<  occupies)(in the std::pair "first" stores layer number, "second" stores group id).
-    GroupPair* m_groups;
-    int        m_groupsSize;
-
     /**
      * Return number of the group id for the given layer, or -1 in case it was not cached before.
      *
@@ -196,10 +183,6 @@ private:
         }
     }
 
-
-    /// Stores layer numbers used by the item.
-    std::vector<int> m_layers;
-
     /**
      * Save layers used by the item.
      *
@@ -242,6 +225,23 @@ private:
     {
         return m_flags == VISIBLE;
     }
+
+
+    VIEW*   m_view;             ///< Current dynamic view the item is assigned to.
+    int     m_flags;            ///< Visibility flags
+    int     m_requiredUpdate;   ///< Flag required for updating
+    int     m_drawPriority;     ///< Order to draw this item in a layer, lowest first
+
+    ///< Helper for storing cached items group ids
+    typedef std::pair<int, int> GroupPair;
+
+    ///< Indexes of cached GAL display lists corresponding to the item (for every layer it.
+    ///<  occupies)(in the std::pair "first" stores layer number, "second" stores group id).
+    GroupPair* m_groups;
+    int        m_groupsSize;
+
+    /// Stores layer numbers used by the item.
+    std::vector<int> m_layers;
 };
 
 
@@ -602,8 +602,9 @@ void VIEW::SetCenter( const VECTOR2D& aCenter )
 }
 
 
-void VIEW::SetCenter( VECTOR2D aCenter, const BOX2D& occultingScreenRect )
+void VIEW::SetCenter( const VECTOR2D& aCenter, const BOX2D& occultingScreenRect )
 {
+    VECTOR2D center( aCenter );
     BOX2D screenRect( VECTOR2D( 0, 0 ), m_gal->GetScreenPixelSize() );
 
     if( !screenRect.Intersects( occultingScreenRect ) )
@@ -621,19 +622,19 @@ void VIEW::SetCenter( VECTOR2D aCenter, const BOX2D& occultingScreenRect )
     if( std::max( topExposed, bottomExposed ) > std::max( leftExposed, rightExposed ) )
     {
         if( topExposed > bottomExposed )
-            aCenter.y += ToWorld( screenRect.GetHeight() / 2 - topExposed / 2 );
+            center.y += ToWorld( screenRect.GetHeight() / 2 - topExposed / 2 );
         else
-            aCenter.y -= ToWorld( screenRect.GetHeight() / 2 - bottomExposed / 2 );
+            center.y -= ToWorld( screenRect.GetHeight() / 2 - bottomExposed / 2 );
     }
     else
     {
         if( leftExposed > rightExposed )
-            aCenter.x += ToWorld( screenRect.GetWidth() / 2 - leftExposed / 2 );
+            center.x += ToWorld( screenRect.GetWidth() / 2 - leftExposed / 2 );
         else
-            aCenter.x -= ToWorld( screenRect.GetWidth() / 2 - rightExposed / 2 );
+            center.x -= ToWorld( screenRect.GetWidth() / 2 - rightExposed / 2 );
     }
 
-    SetCenter( aCenter );
+    SetCenter( center );
 }
 
 
diff --git a/common/view/view_overlay.cpp b/common/view/view_overlay.cpp
index b9a631311c..61437283a3 100644
--- a/common/view/view_overlay.cpp
+++ b/common/view/view_overlay.cpp
@@ -2,6 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2013-2017 CERN
+ * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  * @author Maciej Suminski <maciej.suminski@cern.ch>
  *
@@ -372,14 +373,14 @@ void VIEW_OVERLAY::SetIsFill( bool aIsFillEnabled )
 }
 
 
-void VIEW_OVERLAY::SetGlyphSize( const VECTOR2D aSize )
+void VIEW_OVERLAY::SetGlyphSize( const VECTOR2D& aSize )
 {
     m_commands.push_back( new COMMAND_GLYPH_SIZE( aSize ) );
 }
 
 
 void VIEW_OVERLAY::BitmapText( const wxString& aText, const VECTOR2D& aPosition,
-                             double aRotationAngle )
+                               double aRotationAngle )
 {
     m_commands.push_back( new COMMAND_BITMAP_TEXT( aText, aPosition, aRotationAngle ) );
 }
diff --git a/include/drawing_sheet/ds_data_item.h b/include/drawing_sheet/ds_data_item.h
index b35334dccf..fcd26b1157 100644
--- a/include/drawing_sheet/ds_data_item.h
+++ b/include/drawing_sheet/ds_data_item.h
@@ -2,7 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2013-2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
- * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -71,7 +71,7 @@ class POINT_COORD
 public:
     POINT_COORD() { m_Anchor = RB_CORNER; }
 
-    POINT_COORD( DPOINT aPos, enum CORNER_ANCHOR aAnchor = RB_CORNER )
+    POINT_COORD( const DPOINT& aPos, enum CORNER_ANCHOR aAnchor = RB_CORNER )
     {
         m_Pos = aPos;
         m_Anchor = aAnchor;
@@ -103,7 +103,6 @@ public:
         DS_BITMAP
     };
 
-public:
     DS_DATA_ITEM( DS_ITEM_TYPE aType );
 
     virtual ~DS_DATA_ITEM();
@@ -147,28 +146,28 @@ public:
      *
      * @param aPosition the new position of item, in mm.
      */
-    void MoveTo( DPOINT aPosition );
+    void MoveTo( const DPOINT& aPosition );
 
     /**
      * Move item to a new position.
      *
      * @param aPosition the new position of the starting point in graphic units.
      */
-    void MoveToUi( wxPoint aPosition );
+    void MoveToUi( const wxPoint& aPosition );
 
     /**
      * Move the starting point of the item to a new position.
      *
      * @param aPosition the new position of the starting point, in mm.
      */
-    void MoveStartPointTo( DPOINT aPosition );
+    void MoveStartPointTo( const DPOINT& aPosition );
 
     /**
      * Move the starting point of the item to a new position.
      *
      * @param aPosition is the new position of item in graphic units.
      */
-    void MoveStartPointToUi( wxPoint aPosition );
+    void MoveStartPointToUi( const wxPoint& aPosition );
 
 
     /**
@@ -178,7 +177,7 @@ public:
      *
      * @param aPosition is the new position of the ending point, in mm.
      */
-    void MoveEndPointTo( DPOINT aPosition );
+    void MoveEndPointTo( const DPOINT& aPosition );
 
     /**
      * Move the ending point of the item to a new position.
@@ -187,7 +186,7 @@ public:
      *
      * @param aPosition is the new position of the ending point in graphic units
      */
-    void MoveEndPointToUi( wxPoint aPosition );
+    void MoveEndPointToUi( const wxPoint& aPosition );
 
     /**
      * @return true if the item is inside the rectangle defined by the 4 corners, false otherwise.
@@ -196,13 +195,6 @@ public:
 
     const wxString GetClassName() const;
 
-protected:
-    DS_ITEM_TYPE   m_type;
-    PAGE_OPTION    m_pageOption;
-
-    std::vector<DS_DRAW_ITEM_BASE*> m_drawItems;
-
-public:
     wxString       m_Name;               // a name used in drawing sheet editor to identify items
     wxString       m_Info;               // a comment, only useful in drawing sheet editor
     POINT_COORD    m_Pos;
@@ -211,6 +203,12 @@ public:
     int            m_RepeatCount;        // repeat count for duplicate items
     DPOINT         m_IncrementVector;    // for duplicate items: move vector for position increment
     int            m_IncrementLabel;
+
+protected:
+    DS_ITEM_TYPE   m_type;
+    PAGE_OPTION    m_pageOption;
+
+    std::vector<DS_DRAW_ITEM_BASE*> m_drawItems;
 };
 
 
@@ -234,7 +232,7 @@ public:
     }
 
     /**
-     * Closes the current contour, by storing the index of the last corner of the current
+     * Close the current contour, by storing the index of the last corner of the current
      * polygon in m_polyIndexEnd.
      */
     void CloseContour()
@@ -251,7 +249,7 @@ public:
      * @param aContour is the index of the contour.
      * @return the index of the first corner of the contour \a aCountour.
      */
-    unsigned GetPolyIndexStart( unsigned aContour) const
+    unsigned GetPolyIndexStart( unsigned aContour ) const
     {
         if( aContour == 0 )
             return 0;
@@ -263,7 +261,7 @@ public:
      * @param aContour is the index of the contour.
      * @return the index of the last corner of the contour \a aCountour.
      */
-    unsigned GetPolyIndexEnd( unsigned aContour) const
+    unsigned GetPolyIndexEnd( unsigned aContour ) const
     {
         return m_polyIndexEnd[aContour];
     }
@@ -326,7 +324,6 @@ public:
      */
     void SetConstrainedTextSize();
 
-
     /**
      * Replace the '\''n' sequence by EOL and the sequence  '\''\' by only one '\'
      * inside m_FullText
diff --git a/include/drawing_sheet/ds_data_model.h b/include/drawing_sheet/ds_data_model.h
index 6799213bd2..e3c40632dc 100644
--- a/include/drawing_sheet/ds_data_model.h
+++ b/include/drawing_sheet/ds_data_model.h
@@ -2,7 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2013-2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
- * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -101,12 +101,12 @@ public:
      *
      * @param aOutputString is a wxString to store the S expr string
      */
-    void SaveInString( wxString& aOutputString );
+    void SaveInString( const wxString& aOutputString );
 
     /**
      * Fill the given string with an S-expr serialization of the WS_DATA_ITEMs.
      */
-    void SaveInString( std::vector<DS_DATA_ITEM*> aItemsList, wxString& aOutputString );
+    void SaveInString( std::vector<DS_DATA_ITEM*>& aItemsList, const wxString& aOutputString );
 
     void Append( DS_DATA_ITEM* aItem );
     void Remove( DS_DATA_ITEM* aItem );
@@ -212,8 +212,6 @@ private:
     double m_rightMargin;           // the right page margin in mm
     double m_topMargin;             // the top page margin in mm
     double m_bottomMargin;          // the bottom page margin in mm
-
-
 };
 
 #endif      // DS_DATA_MODEL_H
diff --git a/include/drawing_sheet/ds_draw_item.h b/include/drawing_sheet/ds_draw_item.h
index ad1640a17e..00b510c67f 100644
--- a/include/drawing_sheet/ds_draw_item.h
+++ b/include/drawing_sheet/ds_draw_item.h
@@ -2,7 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2013-2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
- * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -65,7 +65,7 @@ public:
 
     void ViewGetLayers( int aLayers[], int& aCount ) const override;
 
-    virtual void SetEnd( wxPoint aPos ) { /* not all types will need this */ }
+    virtual void SetEnd( const wxPoint& aPos ) { /* not all types will need this */ }
 
     virtual int GetPenWidth() const
     {
@@ -131,9 +131,9 @@ public:
     virtual wxString GetClass() const override { return wxT( "DS_DRAW_ITEM_LINE" ); }
 
     const wxPoint&  GetStart() const { return m_start; }
-    void SetStart( wxPoint aPos ) { m_start = aPos; }
+    void SetStart( const wxPoint& aPos ) { m_start = aPos; }
     const wxPoint&  GetEnd() const { return m_end; }
-    void SetEnd( wxPoint aPos ) override { m_end = aPos; }
+    void SetEnd( const wxPoint& aPos ) override { m_end = aPos; }
 
     wxPoint GetPosition() const override { return GetStart(); }
     void SetPosition( const wxPoint& aPos ) override { SetStart( aPos ); }
@@ -217,9 +217,9 @@ public:
     virtual wxString GetClass() const override { return wxT( "DS_DRAW_ITEM_RECT" ); }
 
     const wxPoint&  GetStart() const { return m_start; }
-    void SetStart( wxPoint aPos ) { m_start = aPos; }
+    void SetStart( const wxPoint& aPos ) { m_start = aPos; }
     const wxPoint&  GetEnd() const { return m_end; }
-    void SetEnd( wxPoint aPos ) override { m_end = aPos; }
+    void SetEnd( const wxPoint& aPos ) override { m_end = aPos; }
 
     wxPoint GetPosition() const override { return GetStart(); }
     void SetPosition( const wxPoint& aPos ) override { SetStart( aPos ); }
@@ -261,10 +261,10 @@ public:
 
     virtual wxString GetClass() const override { return wxT( "DS_DRAW_ITEM_PAGE" ); }
 
-    void SetPageSize( wxSize aSize ) { m_pageSize = aSize; }
+    void SetPageSize( const wxSize& aSize ) { m_pageSize = aSize; }
     wxSize GetPageSize() const { return m_pageSize; }
     const wxPoint& GetMarkerPos() const { return m_markerPos; }
-    void SetMarkerPos( wxPoint aPos ) { m_markerPos = aPos; }
+    void SetMarkerPos( const wxPoint& aPos ) { m_markerPos = aPos; }
     double GetMarkerSize() const { return m_markerSize; }
 
     wxPoint GetPosition() const override { return wxPoint( 0, 0 ); }
@@ -297,8 +297,8 @@ private:
 class DS_DRAW_ITEM_TEXT : public DS_DRAW_ITEM_BASE, public EDA_TEXT
 {
 public:
-    DS_DRAW_ITEM_TEXT( DS_DATA_ITEM* aPeer, int aIndex, wxString& aText, wxPoint aPos,
-                       wxSize aSize, int aPenWidth, bool aItalic = false,
+    DS_DRAW_ITEM_TEXT( DS_DATA_ITEM* aPeer, int aIndex, const wxString& aText, const wxPoint& aPos,
+                       const wxSize& aSize, int aPenWidth, bool aItalic = false,
                        bool aBold = false ) :
             DS_DRAW_ITEM_BASE( aPeer, aIndex, WSG_TEXT_T),
             EDA_TEXT( aText )
diff --git a/include/project/board_project_settings.h b/include/project/board_project_settings.h
index 666ac667ae..09835dcfa8 100644
--- a/include/project/board_project_settings.h
+++ b/include/project/board_project_settings.h
@@ -123,12 +123,6 @@ enum class RATSNEST_MODE
  */
 struct LAYER_PRESET
 {
-    wxString     name;          ///< A name for this layer set
-    LSET         layers;        ///< Board layers that are visible
-    GAL_SET      renderLayers;  ///< Render layers (e.g. object types) that are visible
-    PCB_LAYER_ID activeLayer;   ///< Optional layer to set active when this preset is loaded
-    bool         readOnly;      ///< True if this is a read-only (built-in) preset
-
     LAYER_PRESET( const wxString& aName = wxEmptyString ) :
             name( aName ),
             activeLayer( UNSELECTED_LAYER )
@@ -161,6 +155,12 @@ struct LAYER_PRESET
     {
         return aOther.layers == layers && aOther.renderLayers == renderLayers;
     }
+
+    wxString     name;          ///< A name for this layer set
+    LSET         layers;        ///< Board layers that are visible
+    GAL_SET      renderLayers;  ///< Render layers (e.g. object types) that are visible
+    PCB_LAYER_ID activeLayer;   ///< Optional layer to set active when this preset is loaded
+    bool         readOnly;      ///< True if this is a read-only (built-in) preset
 };
 
 
diff --git a/include/project/net_settings.h b/include/project/net_settings.h
index e170dbe784..12ca712cf4 100644
--- a/include/project/net_settings.h
+++ b/include/project/net_settings.h
@@ -2,6 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2020 CERN
+ * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
  * @author Jon Evans <jon@craftyjon.com>
  *
  * This program is free software: you can redistribute it and/or modify it
@@ -46,7 +47,7 @@ public:
      * A map of fully-qualified net names to colors used in the board context.
      * Since these color overrides are for the board, buses are not included here.
      * Only nets that the user has assigned custom colors to will be in this list.
-     * Nets that no longer exist will be deleted during a netlist read in PcbNew.
+     * Nets that no longer exist will be deleted during a netlist read in Pcbnew.
      */
     std::map<wxString, KIGFX::COLOR4D> m_PcbNetColors;
 
@@ -54,8 +55,9 @@ public:
     const wxString& GetNetclassName( const wxString& aNetName ) const;
 
     /**
-     * Parses a bus vector (e.g. A[7..0]) into name, begin, and end.
-     * Ensures that begin and end are positive and that end > begin.
+     * Parse a bus vector (e.g. A[7..0]) into name, begin, and end.
+     *
+     * Ensure that begin and end are positive and that end > begin.
      *
      * @param aBus is a bus vector label string
      * @param aName out is the bus name, e.g. "A"
@@ -66,18 +68,18 @@ public:
                                 std::vector<wxString>* aMemberList );
 
     /**
-     * Parses a bus group label into the name and a list of components.
+     * Parse a bus group label into the name and a list of components.
      *
      * @param aGroup is the input label, e.g. "USB{DP DM}"
      * @param name is the output group name, e.g. "USB"
      * @param aMemberList is a list of member strings, e.g. "DP", "DM"
      * @return true if aGroup was successfully parsed
      */
-    static bool ParseBusGroup( wxString aGroup, wxString* name,
+    static bool ParseBusGroup( const wxString& aGroup, wxString* name,
                                std::vector<wxString>* aMemberList );
 
     /**
-     * Explodes the list of netclass assignments to include atomic members of composite labels
+     * Explode the list of netclass assignments to include atomic members of composite labels
      * (buses).
      *
      * @param aRebuildFromScratch indicates the assignments should be rebuilt from the netclass
diff --git a/include/project/project_file.h b/include/project/project_file.h
index 4342c29e43..9f2fc6c9d7 100644
--- a/include/project/project_file.h
+++ b/include/project/project_file.h
@@ -101,22 +101,10 @@ protected:
 
     wxString getLegacyFileExt() const override;
 
-private:
-
-    /// An list of schematic sheets in this project
-    std::vector<FILE_INFO_PAIR> m_sheets;
-
-    /// A list of board files in this project
-    std::vector<FILE_INFO_PAIR> m_boards;
-
-    /// A link to the owning PROJECT
-    PROJECT* m_project;
-
     /**
      * Below are project-level settings that have not been moved to a dedicated file
      */
 public:
-
     /**
      * Shared params, used by more than one application
      */
@@ -179,6 +167,16 @@ public:
 
     /// List of stored layer presets
     std::vector<LAYER_PRESET> m_LayerPresets;
+
+private:
+    /// An list of schematic sheets in this project
+    std::vector<FILE_INFO_PAIR> m_sheets;
+
+    /// A list of board files in this project
+    std::vector<FILE_INFO_PAIR> m_boards;
+
+    /// A link to the owning PROJECT
+    PROJECT* m_project;
 };
 
 // Specializations to allow directly reading/writing FILE_INFO_PAIRs from JSON
diff --git a/include/project/project_local_settings.h b/include/project/project_local_settings.h
index 8f095eb98f..1049224aef 100644
--- a/include/project/project_local_settings.h
+++ b/include/project/project_local_settings.h
@@ -2,6 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2020 CERN
+ * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
  * @author Jon Evans <jon@craftyjon.com>
  *
  * This program is free software: you can redistribute it and/or modify it
@@ -65,8 +66,13 @@ public:
         m_project = aProject;
     }
 
-protected:
+    void SaveFileState( const wxString& aFileName, const WINDOW_SETTINGS* aWindowCfg, bool aOpen );
 
+    const PROJECT_FILE_STATE* GetFileState( const wxString& aFileName );
+
+    void ClearFileState();
+
+protected:
     wxString getFileExt() const override
     {
         return ProjectLocalSettingsFileExtension;
@@ -77,11 +83,6 @@ protected:
         return wxT( "NO_SUCH_FILE_EXTENSION" );
     }
 
-private:
-
-    /// A link to the owning project
-    PROJECT* m_project;
-
 public:
 
     /**
@@ -136,11 +137,9 @@ public:
     /// State of the selection filter widget
     SELECTION_FILTER_OPTIONS m_SelectionFilter;
 
-    void SaveFileState( const wxString& aFileName, const WINDOW_SETTINGS* aWindowCfg, bool aOpen );
-
-    const PROJECT_FILE_STATE* GetFileState( const wxString& aFileName );
-
-    void ClearFileState();
+private:
+    /// A link to the owning project
+    PROJECT* m_project;
 };
 
 #endif
diff --git a/include/view/view.h b/include/view/view.h
index ed791777ea..0220c4e3ef 100644
--- a/include/view/view.h
+++ b/include/view/view.h
@@ -323,7 +323,7 @@ public:
      * @param aCenter: the new center point, in world space coordinates.
      * @param occultingScreenRect: the occulting rect, in screen space coordinates.
      */
-    void SetCenter( VECTOR2D aCenter, const BOX2D& occultingScreenRect );
+    void SetCenter( const VECTOR2D& aCenter, const BOX2D& occultingScreenRect );
 
     /**
      * Return the center point of this VIEW (in world space coordinates).
diff --git a/include/view/view_overlay.h b/include/view/view_overlay.h
index 44cad03b4a..ec2b143234 100644
--- a/include/view/view_overlay.h
+++ b/include/view/view_overlay.h
@@ -2,6 +2,7 @@
  * This program source code file is part of KiCad, a free EDA CAD application.
  *
  * Copyright (C) 2013-2017 CERN
+ * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  * @author Maciej Suminski <maciej.suminski@cern.ch>
  *
@@ -89,15 +90,14 @@ public:
     void Polyline( const SHAPE_LINE_CHAIN& aPolyLine );
     void Polygon( const VECTOR2D aPointList[], int aListSize );
 
-    void BitmapText( const wxString& aText, const VECTOR2D& aPosition,
-                             double aRotationAngle );
-    
+    void BitmapText( const wxString& aText, const VECTOR2D& aPosition, double aRotationAngle );
+
     // Draw settings
     void SetIsFill( bool aIsFillEnabled );
     void SetIsStroke( bool aIsStrokeEnabled );
     void SetFillColor( const COLOR4D& aColor );
     void SetStrokeColor( const COLOR4D& aColor );
-    void SetGlyphSize( const VECTOR2D aSize );
+    void SetGlyphSize( const VECTOR2D& aSize );
     void SetLineWidth( double aLineWidth );
 
     const COLOR4D& GetStrokeColor() const { return m_strokeColor; }
diff --git a/pcbnew/connectivity/connectivity_items.h b/pcbnew/connectivity/connectivity_items.h
index b9896fe6f8..67551cb460 100644
--- a/pcbnew/connectivity/connectivity_items.h
+++ b/pcbnew/connectivity/connectivity_items.h
@@ -114,7 +114,7 @@ public:
         return m_noline;
     }
 
-    inline void SetCluster( std::shared_ptr<CN_CLUSTER> aCluster )
+    inline void SetCluster( std::shared_ptr<CN_CLUSTER>& aCluster )
     {
         m_cluster = aCluster;
     }
@@ -126,7 +126,7 @@ public:
 
     /**
      * The anchor point is dangling if the parent is a track and this anchor point is not
-     * connected to another item ( track, vas pad or zone) or if the parent is a via and
+     * connected to another item ( track, vias pad or zone) or if the parent is a via and
      * this anchor point is connected to only one track and not to another item.
      *
      * @return true if this anchor is dangling.
@@ -323,7 +323,7 @@ public:
         return ContainsPoint( anchor->Pos(), 0 );
     }
 
-    bool ContainsPoint( const VECTOR2I p, int aAccuracy = 0 ) const
+    bool ContainsPoint( const VECTOR2I& p, int aAccuracy = 0 ) const
     {
         ZONE* zone = static_cast<ZONE*>( Parent() );
         int clearance = aAccuracy;
@@ -397,7 +397,7 @@ public:
     CN_ITEM* operator[] ( int aIndex ) { return m_items[aIndex]; }
 
     template <class T>
-    void FindNearby( CN_ITEM *aItem, T aFunc )
+    void FindNearby( CN_ITEM* aItem, T aFunc )
     {
         m_index.Query( aItem->BBox(), aItem->Layers(), aFunc );
     }