Skip to content

Commit

Permalink
Add clang-tidy performance checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjcarroll committed Jan 15, 2019
1 parent dbd53fb commit 804e9cd
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Checks: '-*,bugprone-*,modernize-*,-modernize-use-equals-delete,-modernize-use-emplace,readability-identifier-naming'
Checks: '-*,bugprone-*,modernize-*,performance-*,-modernize-use-equals-delete,-modernize-use-emplace,readability-identifier-naming'
CheckOptions:
- { key: readability-identifier-naming.NamespaceCase, value: lower_case }
- { key: readability-identifier-naming.ClassCase, value: CamelCase }
Expand Down
5 changes: 3 additions & 2 deletions include/ignition/gazebo/SystemLoader.hh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ namespace ignition
/// \brief Load and instantiate system plugin from an SDF element.
/// \param[in] _sdf SDF Element describing plugin instance to be loaded.
/// \returns Shared pointer to system instance or nullptr.
public: std::optional<SystemPluginPtr> LoadPlugin(sdf::ElementPtr _sdf);
public: std::optional<SystemPluginPtr> LoadPlugin(
const sdf::ElementPtr &_sdf);

/// \brief Load and instantiate system plugin from name/filename.
/// \param[in] _filename Shared library filename to load plugin from.
Expand All @@ -63,7 +64,7 @@ namespace ignition
public: std::optional<SystemPluginPtr> LoadPlugin(
const std::string &_filename,
const std::string &_name,
sdf::ElementPtr _sdf);
const sdf::ElementPtr &_sdf);

/// \brief Makes a printable string with info about systems
/// \returns A pretty string
Expand Down
6 changes: 4 additions & 2 deletions include/ignition/gazebo/components/SimpleWrapper.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define IGNITION_GAZEBO_COMPONENTS_SIMPLEWRAPPER_HH_

#include <memory>
#include <utility>

#include <ignition/gazebo/config.hh>
#include <ignition/gazebo/Export.hh>
Expand Down Expand Up @@ -59,15 +60,16 @@ namespace components

/// \brief Move Constructor
/// \param[in] _simpleWrapper SimpleWrapper component to move.
public: SimpleWrapper(SimpleWrapper &&_simpleWrapper) = default;
public: SimpleWrapper(SimpleWrapper &&_simpleWrapper) noexcept = default;

/// \brief Destructor.
public: virtual ~SimpleWrapper() = default;

/// \brief Move assignment operator.
/// \param[in] _simpleWrapper SimpleWrapper component to move.
/// \return Reference to this.
public: SimpleWrapper &operator=(SimpleWrapper &&_simpleWrapper) = default;
public: SimpleWrapper &operator=(
SimpleWrapper &&_simpleWrapper) noexcept = default;

/// \brief Copy assignment operator.
/// \param[in] _simpleWrapper SimpleWrapper component to copy.
Expand Down
4 changes: 2 additions & 2 deletions src/Conversions_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ TEST(Conversions, Gui)
EXPECT_TRUE(guiMsg.fullscreen());
ASSERT_EQ(2, guiMsg.plugin_size());

auto plugin1 = guiMsg.plugin(0);
const auto &plugin1 = guiMsg.plugin(0);
EXPECT_EQ("plugin-file-1", plugin1.filename());
EXPECT_EQ("plugin-1", plugin1.name());

EXPECT_NE(plugin1.innerxml().find(
"<banana>3</banana>"),
std::string::npos);

auto plugin2 = guiMsg.plugin(1);
const auto &plugin2 = guiMsg.plugin(1);
EXPECT_EQ("plugin-file-2", plugin2.filename());
EXPECT_EQ("plugin-2", plugin2.name());
EXPECT_NE(plugin2.innerxml().find(
Expand Down
4 changes: 3 additions & 1 deletion src/Model_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ TEST(ModelTest, CopyConstructor)
ignition::gazebo::Entity id(3);
ignition::gazebo::Model model(id);

ignition::gazebo::Model modelCopy(model);
// Marked nolint because we are specifically testing copy
// constructor here (clang wants unnecessary copies removed)
ignition::gazebo::Model modelCopy(model); // NOLINT
EXPECT_EQ(model.Entity(), modelCopy.Entity());
}

Expand Down
2 changes: 1 addition & 1 deletion src/ServerPrivate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ bool ServerPrivate::WorldsService(ignition::msgs::StringMsg_V &_res)

_res.Clear();

for (auto name : this->worldNames)
for (const auto &name : this->worldNames)
{
_res.add_data(name);
}
Expand Down
7 changes: 4 additions & 3 deletions src/SystemLoader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class ignition::gazebo::SystemLoaderPrivate
//////////////////////////////////////////////////
public: bool InstantiateSystemPlugin(const std::string &_filename,
const std::string &_name,
sdf::ElementPtr /*_sdf*/,
const sdf::ElementPtr &/*_sdf*/,
ignition::plugin::PluginPtr &_plugin)
{
ignition::common::SystemPaths systemPaths;
Expand Down Expand Up @@ -149,7 +149,7 @@ void SystemLoader::AddSystemPluginPath(const std::string &_path)
std::optional<SystemPluginPtr> SystemLoader::LoadPlugin(
const std::string &_filename,
const std::string &_name,
sdf::ElementPtr _sdf)
const sdf::ElementPtr &_sdf)
{
ignition::plugin::PluginPtr plugin;

Expand All @@ -173,7 +173,8 @@ std::optional<SystemPluginPtr> SystemLoader::LoadPlugin(
}

//////////////////////////////////////////////////
std::optional<SystemPluginPtr> SystemLoader::LoadPlugin(sdf::ElementPtr _sdf)
std::optional<SystemPluginPtr> SystemLoader::LoadPlugin(
const sdf::ElementPtr &_sdf)
{
if (nullptr == _sdf)
{
Expand Down
12 changes: 6 additions & 6 deletions src/gui_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
* limitations under the License.
*
*/

#include <gflags/gflags.h>
#include <csignal>
#include <tinyxml2.h>

#include <ignition/common/Console.hh>
#include <csignal>
#include <iostream>

#include <ignition/common/Console.hh>
#include <ignition/gui/Application.hh>
#include <ignition/gui/MainWindow.hh>

#include <iostream>

#include "ignition/gazebo/config.hh"
#include "ignition/gazebo/gui/TmpIface.hh"

Expand Down Expand Up @@ -210,8 +210,8 @@ int main(int _argc, char **_argv)

for (int p = 0; p < res.plugin_size(); ++p)
{
auto plugin = res.plugin(p);
auto fileName = plugin.filename();
const auto &plugin = res.plugin(p);
const auto &fileName = plugin.filename();
std::string pluginStr = "<plugin filename='" + fileName + "'>" +
plugin.innerxml() + "</plugin>";

Expand Down
9 changes: 4 additions & 5 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,18 @@
* limitations under the License.
*
*/
#include <csignal>
#include <gflags/gflags.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <gflags/gflags.h>

#include <csignal>
#include <iostream>

#include <ignition/common/Console.hh>
#include <ignition/common/SignalHandler.hh>
#include <ignition/common/Time.hh>

#include <csignal>
#include <iostream>

#include "ignition/gazebo/config.hh"

// Gflag command line argument definitions
Expand Down
8 changes: 4 additions & 4 deletions test/integration/diff_drive_system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,19 @@ class Relay

public: Relay &OnPreUpdate(MockSystem::CallbackType _cb)
{
this->mockSystem->preUpdateCallback = _cb;
this->mockSystem->preUpdateCallback = std::move(_cb);
return *this;
}

public: Relay &OnUpdate(MockSystem::CallbackType _cb)
{
this->mockSystem->updateCallback = _cb;
this->mockSystem->updateCallback = std::move(_cb);
return *this;
}

public: Relay &OnPostUpdate(MockSystem::CallbackTypeConst _cb)
{
this->mockSystem->postUpdateCallback = _cb;
this->mockSystem->postUpdateCallback = std::move(_cb);
return *this;
}

Expand Down Expand Up @@ -121,7 +121,7 @@ TEST_P(DiffDriveTest, PublishCmd)

EXPECT_EQ(1000u, poses.size());

for (auto pose : poses)
for (const auto &pose : poses)
{
EXPECT_EQ(poses[0], pose);
}
Expand Down
6 changes: 3 additions & 3 deletions test/integration/each_new_erased.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ class Relay

public: Relay &OnPreUpdate(gazebo::MockSystem::CallbackType _cb)
{
this->mockSystem->preUpdateCallback = _cb;
this->mockSystem->preUpdateCallback = std::move(_cb);
return *this;
}

public: Relay &OnUpdate(gazebo::MockSystem::CallbackType _cb)
{
this->mockSystem->updateCallback = _cb;
this->mockSystem->updateCallback = std::move(_cb);
return *this;
}

public: Relay &OnPostUpdate(gazebo::MockSystem::CallbackTypeConst _cb)
{
this->mockSystem->postUpdateCallback = _cb;
this->mockSystem->postUpdateCallback = std::move(_cb);
return *this;
}

Expand Down
3 changes: 2 additions & 1 deletion test/integration/examples_build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ void ExamplesBuild::Build(const std::string &_type)
auto base = ignition::common::basename(*dirIter);

// Source directory for this example
auto sourceDir = examplesDir + "/" + base;
auto sourceDir = examplesDir;
sourceDir += "/" + base;
ASSERT_TRUE(ignition::common::exists(sourceDir));
igndbg << "Source: " << sourceDir << std::endl;

Expand Down
6 changes: 3 additions & 3 deletions test/integration/physics_system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,19 @@ class Relay

public: Relay & OnPreUpdate(gazebo::MockSystem::CallbackType _cb)
{
this->mockSystem->preUpdateCallback = _cb;
this->mockSystem->preUpdateCallback = std::move(_cb);
return *this;
}

public: Relay & OnUpdate(gazebo::MockSystem::CallbackType _cb)
{
this->mockSystem->updateCallback = _cb;
this->mockSystem->updateCallback = std::move(_cb);
return *this;
}

public: Relay & OnPostUpdate(gazebo::MockSystem::CallbackTypeConst _cb)
{
this->mockSystem->postUpdateCallback = _cb;
this->mockSystem->postUpdateCallback = std::move(_cb);
return *this;
}

Expand Down

0 comments on commit 804e9cd

Please sign in to comment.