Skip to content

Commit

Permalink
Use always const reference in for-ranged loop instead of copying prim…
Browse files Browse the repository at this point in the history
…itive data types
  • Loading branch information
Heiko Thiel committed Mar 7, 2019
1 parent b8aba3a commit 7fea1c0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
18 changes: 9 additions & 9 deletions common/include/pcl/common/impl/centroid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pcl::compute3DCentroid (const pcl::PointCloud<PointT> &cloud,
// If the data is dense, we don't need to check for NaN
if (cloud.is_dense)
{
for (const int index : indices)
for (const int &index : indices)
{
centroid[0] += cloud[index].x;
centroid[1] += cloud[index].y;
Expand All @@ -149,7 +149,7 @@ pcl::compute3DCentroid (const pcl::PointCloud<PointT> &cloud,
else
{
unsigned cp = 0;
for (const int index : indices)
for (const int &index : indices)
{
// Check if the point is invalid
if (!isFinite (cloud [index]))
Expand Down Expand Up @@ -300,7 +300,7 @@ pcl::computeCovarianceMatrix (const pcl::PointCloud<PointT> &cloud,
{
point_count = 0;
// For each point in the cloud
for (const int index : indices)
for (const int &index : indices)
{
// Check if the point is invalid
if (!isFinite (cloud[index]))
Expand Down Expand Up @@ -434,7 +434,7 @@ pcl::computeCovarianceMatrix (const pcl::PointCloud<PointT> &cloud,
if (cloud.is_dense)
{
point_count = static_cast<unsigned int> (indices.size ());
for (const int index : indices)
for (const int &index : indices)
{
//const PointT& point = cloud[*iIt];
accu [0] += cloud[index].x * cloud[index].x;
Expand All @@ -448,7 +448,7 @@ pcl::computeCovarianceMatrix (const pcl::PointCloud<PointT> &cloud,
else
{
point_count = 0;
for (const int index : indices)
for (const int &index : indices)
{
if (!isFinite (cloud[index]))
continue;
Expand Down Expand Up @@ -562,7 +562,7 @@ pcl::computeMeanAndCovarianceMatrix (const pcl::PointCloud<PointT> &cloud,
if (cloud.is_dense)
{
point_count = indices.size ();
for (const int index : indices)
for (const int &index : indices)
{
//const PointT& point = cloud[*iIt];
accu [0] += cloud[index].x * cloud[index].x;
Expand All @@ -579,7 +579,7 @@ pcl::computeMeanAndCovarianceMatrix (const pcl::PointCloud<PointT> &cloud,
else
{
point_count = 0;
for (const int index : indices)
for (const int &index : indices)
{
if (!isFinite (cloud[index]))
continue;
Expand Down Expand Up @@ -886,10 +886,10 @@ pcl::computeCentroid (const pcl::PointCloud<PointInT>& cloud,
pcl::CentroidPoint<PointInT> cp;

if (cloud.is_dense)
for (const int index : indices)
for (const int &index : indices)
cp.add (cloud[index]);
else
for (const int index : indices)
for (const int &index : indices)
if (pcl::isFinite (cloud[index]))
cp.add (cloud[index]);

Expand Down
10 changes: 5 additions & 5 deletions common/include/pcl/common/impl/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pcl::getMeanStd (const std::vector<float> &values, double &mean, double &stddev)

double sum = 0, sq_sum = 0;

for (const float value : values)
for (const float &value : values)
{
sum += value;
sq_sum += value * value;
Expand Down Expand Up @@ -324,7 +324,7 @@ pcl::getMinMax3D (const pcl::PointCloud<PointT> &cloud, const pcl::PointIndices
// If the data is dense, we don't need to check for NaN
if (cloud.is_dense)
{
for (const int index : indices.indices)
for (const int &index : indices.indices)
{
pcl::Array4fMapConst pt = cloud.points[index].getArray4fMap ();
min_p = min_p.min (pt);
Expand All @@ -334,7 +334,7 @@ pcl::getMinMax3D (const pcl::PointCloud<PointT> &cloud, const pcl::PointIndices
// NaN or Inf values could exist => check for them
else
{
for (const int index : indices.indices)
for (const int &index : indices.indices)
{
// Check if the point is invalid
if (!std::isfinite (cloud.points[index].x) ||
Expand All @@ -361,7 +361,7 @@ pcl::getMinMax3D (const pcl::PointCloud<PointT> &cloud, const std::vector<int> &
// If the data is dense, we don't need to check for NaN
if (cloud.is_dense)
{
for (const int index : indices)
for (const int &index : indices)
{
pcl::Array4fMapConst pt = cloud.points[index].getArray4fMap ();
min_pt = min_pt.array ().min (pt);
Expand All @@ -371,7 +371,7 @@ pcl::getMinMax3D (const pcl::PointCloud<PointT> &cloud, const std::vector<int> &
// NaN or Inf values could exist => check for them
else
{
for (const int index : indices)
for (const int &index : indices)
{
// Check if the point is invalid
if (!std::isfinite (cloud.points[index].x) ||
Expand Down
2 changes: 1 addition & 1 deletion common/src/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pcl::getMeanStdDev (const std::vector<float> &values, double &mean, double &stdd
{
double sum = 0, sq_sum = 0;

for (const float value : values)
for (const float &value : values)
{
sum += value;
sq_sum += value * value;
Expand Down

0 comments on commit 7fea1c0

Please sign in to comment.