From 24bde6fd61e2be78c956cf6c6f238f3dce0d81be Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Wed, 13 Apr 2016 13:59:26 +0200 Subject: [PATCH] cleanup: const in constructors, remove std::move * 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) --- include/mapbox/geojsonvt/clip.hpp | 2 -- include/mapbox/geojsonvt/transform.hpp | 2 +- include/mapbox/geojsonvt/types.hpp | 14 +++++++------- include/mapbox/geojsonvt/wrap.hpp | 2 +- src/clip.cpp | 6 +++--- src/convert.cpp | 13 +++++++------ src/geojsonvt.cpp | 8 ++++---- src/tile.cpp | 2 +- test/util.cpp | 2 +- 9 files changed, 25 insertions(+), 26 deletions(-) diff --git a/include/mapbox/geojsonvt/clip.hpp b/include/mapbox/geojsonvt/clip.hpp index 2527cb6..a41b6fe 100644 --- a/include/mapbox/geojsonvt/clip.hpp +++ b/include/mapbox/geojsonvt/clip.hpp @@ -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); }; diff --git a/include/mapbox/geojsonvt/transform.hpp b/include/mapbox/geojsonvt/transform.hpp index c6a24b1..fd6376d 100644 --- a/include/mapbox/geojsonvt/transform.hpp +++ b/include/mapbox/geojsonvt/transform.hpp @@ -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 { diff --git a/include/mapbox/geojsonvt/types.hpp b/include/mapbox/geojsonvt/types.hpp index 3c9f234..58c4963 100644 --- a/include/mapbox/geojsonvt/types.hpp +++ b/include/mapbox/geojsonvt/types.hpp @@ -12,7 +12,7 @@ namespace mapbox { namespace geojsonvt { struct __attribute__((visibility("default"))) LonLat { - LonLat(std::array coordinates) : lon(coordinates[0]), lat(coordinates[1]) { + LonLat(std::array const& coordinates) : lon(coordinates[0]), lat(coordinates[1]) { } LonLat(double lon_, double lat_) : lon(lon_), lat(lat_) { @@ -55,7 +55,7 @@ class __attribute__((visibility("default"))) ProjectedRing { public: ProjectedRing() { } - ProjectedRing(ProjectedPoints points_) : points(points_) { + ProjectedRing(ProjectedPoints const& points_) : points(points_) { } public: @@ -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_), @@ -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_) { } diff --git a/include/mapbox/geojsonvt/wrap.hpp b/include/mapbox/geojsonvt/wrap.hpp index 924d892..43265e7 100644 --- a/include/mapbox/geojsonvt/wrap.hpp +++ b/include/mapbox/geojsonvt/wrap.hpp @@ -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 { diff --git a/src/clip.cpp b/src/clip.cpp index 8c14ea6..792fbc3 100644 --- a/src/clip.cpp +++ b/src/clip.cpp @@ -65,7 +65,7 @@ std::vector Clip::clip(const std::vector& fe clipped.emplace_back(slices, type, feature.tags, feature.min, feature.max); } - return std::move(clipped); + return clipped; } ProjectedPoints @@ -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, @@ -167,7 +167,7 @@ ProjectedRings Clip::clipGeometry(const ProjectedRings& rings, newSlice(slices, slice, area, dist); } - return std::move(slices); + return slices; } ProjectedRing diff --git a/src/convert.cpp b/src/convert.cpp index 26c5f4e..43ffb5a 100644 --- a/src/convert.cpp +++ b/src/convert.cpp @@ -3,13 +3,14 @@ #include #include -#include -#include #include +#include +#include namespace { -template std::string to_string(const T& value) { +template +std::string to_string(const T& value) { std::ostringstream stream; stream.setf(std::ios::fixed); stream.precision(6); @@ -67,7 +68,7 @@ std::vector Convert::convert(const JSValue& data, double toler convertGeometry(features, {}, data, tolerance); } - return std::move(features); + return features; } void Convert::convertFeature(std::vector& features, @@ -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& lonlats, double tolerance) { @@ -222,7 +223,7 @@ ProjectedRing Convert::projectRing(const std::vector& lonlats, double to Simplify::simplify(ring.points, tolerance); calcSize(ring); - return std::move(ring); + return ring; } ProjectedPoint Convert::projectPoint(const LonLat& p_) { diff --git a/src/geojsonvt.cpp b/src/geojsonvt.cpp index 5e263ea..0e228a6 100644 --- a/src/geojsonvt.cpp +++ b/src/geojsonvt.cpp @@ -1,15 +1,15 @@ #include #include #include -#include #include +#include -#include -#include #include +#include #include -#include #include +#include +#include #include namespace mapbox { diff --git a/src/tile.cpp b/src/tile.cpp index 62a20fa..5d8b750 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -36,7 +36,7 @@ Tile Tile::createTile(std::vector& features, } } - return std::move(tile); + return tile; } void Tile::addFeature(Tile& tile, diff --git a/test/util.cpp b/test/util.cpp index fc480ad..650ee51 100644 --- a/test/util.cpp +++ b/test/util.cpp @@ -201,7 +201,7 @@ std::vector parseJSONTile(const rapidjson::GenericValue parseJSONTile(const std::string& data) {