help compiler to apply RVO ( return the same object by value)

This commit is contained in:
artemp 2015-04-08 13:10:22 +02:00
parent 431c581759
commit 310865a0c3

View file

@ -170,82 +170,75 @@ struct geom_reproj_copy_visitor {
geometry operator() (geometry_empty const&) geometry operator() (geometry_empty const&)
{ {
return std::move(geometry_empty()); return geometry_empty();
} }
geometry operator() (point const& p) geometry operator() (point const& p)
{ {
geometry geom; // default empty
unsigned int intial_err = n_err_; unsigned int intial_err = n_err_;
point new_p = reproject_internal(p, proj_trans_, n_err_); point new_p = reproject_internal(p, proj_trans_, n_err_);
if (n_err_ > intial_err) if (n_err_ > intial_err) return geom;
{ geom = std::move(new_p);
return std::move(geometry_empty()); return geom;
}
return std::move(new_p);
} }
geometry operator() (line_string const& ls) geometry operator() (line_string const& ls)
{ {
geometry geom; // default empty
int intial_err = n_err_; int intial_err = n_err_;
line_string new_ls = reproject_internal(ls, proj_trans_, n_err_); line_string new_ls = reproject_internal(ls, proj_trans_, n_err_);
if (n_err_ > intial_err || new_ls.empty()) if (n_err_ > intial_err || new_ls.empty()) return geom;
{ geom = std::move(new_ls);
return std::move(geometry_empty()); return geom;
}
return std::move(new_ls);
} }
geometry operator() (polygon const& poly) geometry operator() (polygon const& poly)
{ {
geometry geom; // default empty
polygon new_poly = reproject_internal(poly, proj_trans_, n_err_); polygon new_poly = reproject_internal(poly, proj_trans_, n_err_);
if (new_poly.exterior_ring.empty()) if (new_poly.exterior_ring.empty()) return geom;
{ geom = std::move(new_poly);
return std::move(geometry_empty()); return geom;
}
return std::move(new_poly);
} }
geometry operator() (multi_point const& mp) geometry operator() (multi_point const& mp)
{ {
geometry geom; // default empty
multi_point new_mp = reproject_internal(mp, proj_trans_, n_err_); multi_point new_mp = reproject_internal(mp, proj_trans_, n_err_);
if (new_mp.empty()) if (new_mp.empty()) return geom;
{ geom = std::move(new_mp);
return std::move(geometry_empty()); return geom;
}
return std::move(new_mp);
} }
geometry operator() (multi_line_string const& mls) geometry operator() (multi_line_string const& mls)
{ {
geometry geom; // default empty
multi_line_string new_mls = reproject_internal(mls, proj_trans_, n_err_); multi_line_string new_mls = reproject_internal(mls, proj_trans_, n_err_);
if (new_mls.empty()) if (new_mls.empty()) return geom;
{ geom = std::move(new_mls);
return std::move(geometry_empty()); return geom;
}
return std::move(new_mls);
} }
geometry operator() (multi_polygon const& mpoly) geometry operator() (multi_polygon const& mpoly)
{ {
geometry geom; // default empty
multi_polygon new_mpoly = reproject_internal(mpoly, proj_trans_, n_err_); multi_polygon new_mpoly = reproject_internal(mpoly, proj_trans_, n_err_);
if (new_mpoly.empty()) if (new_mpoly.empty()) return geom;
{ geom = std::move(new_mpoly);
return std::move(geometry_empty()); return geom;
}
return std::move(new_mpoly);
} }
geometry operator() (geometry_collection const& c) geometry operator() (geometry_collection const& c)
{ {
geometry geom; // default empty
geometry_collection new_c = reproject_internal(c, proj_trans_, n_err_); geometry_collection new_c = reproject_internal(c, proj_trans_, n_err_);
if (new_c.empty()) if (new_c.empty()) return geom;
{ geom = std::move(new_c);
return std::move(geometry_empty()); return geom;
}
return std::move(new_c);
} }
private: private:
proj_transform const& proj_trans_; proj_transform const& proj_trans_;
unsigned int & n_err_; unsigned int & n_err_;
@ -381,7 +374,7 @@ struct geom_reproj_visitor {
return true; return true;
} }
private: private:
proj_transform const& proj_trans_; proj_transform const& proj_trans_;
}; };