Skip to content

Commit

Permalink
cleanup: const in constructors, remove std::move
Browse files Browse the repository at this point in the history
* pass non built-in arguments by const reference in constructors to avoid creating an extra redundant copy
* replace `return std::move(obj);' with 'return obj;' and let compiler do the work [RVO](https://en.wikipedia.org/wiki/Return_value_optimization)
  • Loading branch information
artemp authored and mourner committed Apr 13, 2016
1 parent cc9a1a5 commit 24bde6f
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 26 deletions.
2 changes: 0 additions & 2 deletions include/mapbox/geojsonvt/clip.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@ class __attribute__((visibility("default"))) Clip {
private:
static ProjectedPoints
clipPoints(const ProjectedPoints& points, double k1, double k2, uint8_t axis);

static ProjectedRings clipGeometry(const ProjectedRings& rings,
double k1,
double k2,
uint8_t axis,
IntersectCallback intersect,
bool closed);

static ProjectedRing
newSlice(ProjectedRings& slices, ProjectedRing& slice, double area, double dist);
};
Expand Down
2 changes: 1 addition & 1 deletion include/mapbox/geojsonvt/transform.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef MAPBOX_GEOJSONVT_TRANSFORM
#define MAPBOX_GEOJSONVT_TRANSFORM

#include "types.hpp"
#include "tile.hpp"
#include "types.hpp"

namespace mapbox {
namespace geojsonvt {
Expand Down
14 changes: 7 additions & 7 deletions include/mapbox/geojsonvt/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace mapbox {
namespace geojsonvt {

struct __attribute__((visibility("default"))) LonLat {
LonLat(std::array<double, 2> coordinates) : lon(coordinates[0]), lat(coordinates[1]) {
LonLat(std::array<double, 2> const& coordinates) : lon(coordinates[0]), lat(coordinates[1]) {
}

LonLat(double lon_, double lat_) : lon(lon_), lat(lat_) {
Expand Down Expand Up @@ -55,7 +55,7 @@ class __attribute__((visibility("default"))) ProjectedRing {
public:
ProjectedRing() {
}
ProjectedRing(ProjectedPoints points_) : points(points_) {
ProjectedRing(ProjectedPoints const& points_) : points(points_) {
}

public:
Expand All @@ -81,11 +81,11 @@ enum class ProjectedFeatureType : uint8_t { Point = 1, LineString = 2, Polygon =

class __attribute__((visibility("default"))) ProjectedFeature {
public:
ProjectedFeature(ProjectedGeometry geometry_,
ProjectedFeature(ProjectedGeometry const& geometry_,
ProjectedFeatureType type_,
Tags tags_,
ProjectedPoint min_ = { 2, 1 }, // initial bbox values;
ProjectedPoint max_ = { -1, 0 }) // coords are usually in [0..1] range
Tags const& tags_,
ProjectedPoint const& min_ = { 2, 1 }, // initial bbox values;
ProjectedPoint const& max_ = { -1, 0 }) // coords are usually in [0..1] range
: geometry(geometry_),
type(type_),
tags(tags_),
Expand Down Expand Up @@ -127,7 +127,7 @@ typedef ProjectedFeatureType TileFeatureType;

class __attribute__((visibility("default"))) TileFeature {
public:
TileFeature(ProjectedGeometry geometry_, TileFeatureType type_, Tags tags_)
TileFeature(ProjectedGeometry const& geometry_, TileFeatureType type_, Tags const& tags_)
: geometry(geometry_), type(type_), tags(tags_) {
}

Expand Down
2 changes: 1 addition & 1 deletion include/mapbox/geojsonvt/wrap.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef MAPBOX_GEOJSONVT_WRAP
#define MAPBOX_GEOJSONVT_WRAP

#include "types.hpp"
#include "clip.hpp"
#include "types.hpp"

namespace mapbox {
namespace geojsonvt {
Expand Down
6 changes: 3 additions & 3 deletions src/clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ std::vector<ProjectedFeature> Clip::clip(const std::vector<ProjectedFeature>& fe
clipped.emplace_back(slices, type, feature.tags, feature.min, feature.max);
}

return std::move(clipped);
return clipped;
}

ProjectedPoints
Expand All @@ -80,7 +80,7 @@ Clip::clipPoints(const ProjectedPoints& points, double k1, double k2, uint8_t ax
}
}

return std::move(slice);
return slice;
}

ProjectedRings Clip::clipGeometry(const ProjectedRings& rings,
Expand Down Expand Up @@ -167,7 +167,7 @@ ProjectedRings Clip::clipGeometry(const ProjectedRings& rings,
newSlice(slices, slice, area, dist);
}

return std::move(slices);
return slices;
}

ProjectedRing
Expand Down
13 changes: 7 additions & 6 deletions src/convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@

#include <array>
#include <cmath>
#include <vector>
#include <string>
#include <sstream>
#include <string>
#include <vector>

namespace {

template <typename T> std::string to_string(const T& value) {
template <typename T>
std::string to_string(const T& value) {
std::ostringstream stream;
stream.setf(std::ios::fixed);
stream.precision(6);
Expand Down Expand Up @@ -67,7 +68,7 @@ std::vector<ProjectedFeature> Convert::convert(const JSValue& data, double toler
convertGeometry(features, {}, data, tolerance);
}

return std::move(features);
return features;
}

void Convert::convertFeature(std::vector<ProjectedFeature>& features,
Expand Down Expand Up @@ -209,7 +210,7 @@ ProjectedFeature Convert::create(Tags tags, ProjectedFeatureType type, Projected
ProjectedFeature feature(geometry, type, tags);
calcBBox(feature);

return std::move(feature);
return feature;
}

ProjectedRing Convert::projectRing(const std::vector<LonLat>& lonlats, double tolerance) {
Expand All @@ -222,7 +223,7 @@ ProjectedRing Convert::projectRing(const std::vector<LonLat>& lonlats, double to
Simplify::simplify(ring.points, tolerance);
calcSize(ring);

return std::move(ring);
return ring;
}

ProjectedPoint Convert::projectPoint(const LonLat& p_) {
Expand Down
8 changes: 4 additions & 4 deletions src/geojsonvt.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#include <mapbox/geojsonvt.hpp>
#include <mapbox/geojsonvt/clip.hpp>
#include <mapbox/geojsonvt/convert.hpp>
#include <mapbox/geojsonvt/wrap.hpp>
#include <mapbox/geojsonvt/transform.hpp>
#include <mapbox/geojsonvt/wrap.hpp>

#include <stack>
#include <cmath>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <unordered_map>
#include <iostream>
#include <stack>
#include <unordered_map>
#include <utility>

namespace mapbox {
Expand Down
2 changes: 1 addition & 1 deletion src/tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Tile Tile::createTile(std::vector<ProjectedFeature>& features,
}
}

return std::move(tile);
return tile;
}

void Tile::addFeature(Tile& tile,
Expand Down
2 changes: 1 addition & 1 deletion test/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ std::vector<TileFeature> parseJSONTile(const rapidjson::GenericValue<rapidjson::
features.emplace_back(std::move(tileFeature));
}

return std::move(features);
return features;
}

std::vector<TileFeature> parseJSONTile(const std::string& data) {
Expand Down

0 comments on commit 24bde6f

Please sign in to comment.