From f4d0c7f032be1b6a672fc5aff0ba93ee1fb79203 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Thu, 1 Jul 2021 08:54:48 +0200 Subject: [PATCH] Remove all the remaining obscure micro-optimizations --- src/map/crs.cpp | 8 ++++---- src/map/gcs.cpp | 18 ++++++------------ src/map/gcs.h | 7 +++---- src/map/geotiff.cpp | 7 +++---- src/map/pcs.cpp | 14 +++++--------- src/map/pcs.h | 4 ++-- src/map/prjfile.cpp | 4 +--- src/map/rmap.cpp | 2 +- 8 files changed, 25 insertions(+), 39 deletions(-) diff --git a/src/map/crs.cpp b/src/map/crs.cpp index 5102e0b0..bbc8fc0a 100644 --- a/src/map/crs.cpp +++ b/src/map/crs.cpp @@ -34,11 +34,11 @@ Projection CRS::projection(const QString &crs) if (!res) return Projection(); - const PCS &pcs = PCS::pcs(epsg); + PCS pcs(PCS::pcs(epsg)); if (!pcs.isNull()) return Projection(pcs); - const GCS &gcs = GCS::gcs(epsg); + GCS gcs(GCS::gcs(epsg)); if (!gcs.isNull()) return Projection(gcs); @@ -54,11 +54,11 @@ Projection CRS::projection(const QString &crs) Projection CRS::projection(int id) { - const PCS &pcs = PCS::pcs(id); + PCS pcs(PCS::pcs(id)); if (!pcs.isNull()) return Projection(pcs); - const GCS &gcs = GCS::gcs(id); + GCS gcs(GCS::gcs(id)); if (!gcs.isNull()) return Projection(gcs); diff --git a/src/map/gcs.cpp b/src/map/gcs.cpp index 7a0e7d7d..3b0bcd89 100644 --- a/src/map/gcs.cpp +++ b/src/map/gcs.cpp @@ -58,21 +58,17 @@ QList GCS::defaults() return list; } -const GCS &GCS::gcs(int id) +GCS GCS::gcs(int id) { - static const GCS null; - for (int i = 0; i < _gcss.size(); i++) if (_gcss.at(i).id() == id) return _gcss.at(i).gcs(); - return null; + return GCS(); } -const GCS &GCS::gcs(int geodeticDatum, int primeMeridian, int angularUnits) +GCS GCS::gcs(int geodeticDatum, int primeMeridian, int angularUnits) { - static const GCS null; - for (int i = 0; i < _gcss.size(); i++) { const Entry &e = _gcss.at(i); if (e.gd() == geodeticDatum && e.gcs().primeMeridian() == primeMeridian @@ -80,18 +76,16 @@ const GCS &GCS::gcs(int geodeticDatum, int primeMeridian, int angularUnits) return e.gcs(); } - return null; + return GCS(); } -const GCS &GCS::gcs(const QString &name) +GCS GCS::gcs(const QString &name) { - static const GCS null; - for (int i = 0; i < _gcss.size(); i++) if (_gcss.at(i).name() == name) return _gcss.at(i).gcs(); - return null; + return GCS(); } void GCS::loadList(const QString &path) diff --git a/src/map/gcs.h b/src/map/gcs.h index 3447ae25..52b09486 100644 --- a/src/map/gcs.h +++ b/src/map/gcs.h @@ -32,10 +32,9 @@ public: Coordinates toWGS84(const Coordinates &c) const; Coordinates fromWGS84(const Coordinates &c) const; - static const GCS &gcs(int id); - static const GCS &gcs(int geodeticDatum, int primeMeridian, - int angularUnits); - static const GCS &gcs(const QString &name); + static GCS gcs(int id); + static GCS gcs(int geodeticDatum, int primeMeridian, int angularUnits); + static GCS gcs(const QString &name); static const GCS &WGS84(); static void loadList(const QString &path); diff --git a/src/map/geotiff.cpp b/src/map/geotiff.cpp index 696add0b..0bb5a272 100644 --- a/src/map/geotiff.cpp +++ b/src/map/geotiff.cpp @@ -359,7 +359,7 @@ Projection::Method GeoTIFF::coordinateTransformation(QMap &kv) bool GeoTIFF::projectedModel(QMap &kv) { if (IS_SET(kv, ProjectedCSTypeGeoKey)) { - const PCS &pcs = PCS::pcs(kv.value(ProjectedCSTypeGeoKey).SHORT); + PCS pcs(PCS::pcs(kv.value(ProjectedCSTypeGeoKey).SHORT)); if (pcs.isNull()) { _errorString = QString("%1: unknown PCS") .arg(kv.value(ProjectedCSTypeGeoKey).SHORT); @@ -370,7 +370,7 @@ bool GeoTIFF::projectedModel(QMap &kv) GCS gcs(geographicCS(kv)); if (gcs.isNull()) return false; - const PCS &pcs = PCS::pcs(gcs, kv.value(ProjectionGeoKey).SHORT); + PCS pcs(PCS::pcs(gcs, kv.value(ProjectionGeoKey).SHORT)); if (pcs.isNull()) { _errorString = QString("%1: unknown projection code") .arg(kv.value(GeographicTypeGeoKey).SHORT) @@ -454,8 +454,7 @@ bool GeoTIFF::projectedModel(QMap &kv) fe = NAN; Projection::Setup setup(lat0, lon0, scale, fe, fn, sp1, sp2); - PCS pcs(gcs, method, setup, lu, CoordinateSystem()); - _projection = Projection(pcs); + _projection = Projection(PCS(gcs, method, setup, lu)); } return true; diff --git a/src/map/pcs.cpp b/src/map/pcs.cpp index 1c9c12de..7910bed7 100644 --- a/src/map/pcs.cpp +++ b/src/map/pcs.cpp @@ -117,26 +117,22 @@ static int projectionSetup(const QList &list, } -const PCS &PCS::pcs(int id) +PCS PCS::pcs(int id) { - static const PCS null; - for (int i = 0; i < _pcss.size(); i++) if (_pcss.at(i).id() == id) return _pcss.at(i).pcs(); - return null; + return PCS(); } -const PCS &PCS::pcs(const GCS &gcs, int proj) +PCS PCS::pcs(const GCS &gcs, int proj) { - static const PCS null; - for (int i = 0; i < _pcss.size(); i++) if (_pcss.at(i).proj() == proj && _pcss.at(i).pcs().gcs() == gcs) return _pcss.at(i).pcs(); - return null; + return PCS(); } void PCS::loadList(const QString &path) @@ -210,7 +206,7 @@ void PCS::loadList(const QString &path) ln); continue; } - const GCS &gcs = GCS::gcs(gcsid); + GCS gcs(GCS::gcs(gcsid)); if (gcs.isNull()) { qWarning("%s:%d: Unknown GCS code", qPrintable(path), ln); continue; diff --git a/src/map/pcs.h b/src/map/pcs.h index d87ec4ba..68dc3379 100644 --- a/src/map/pcs.h +++ b/src/map/pcs.h @@ -36,8 +36,8 @@ public: } static void loadList(const QString &path); - static const PCS &pcs(int id); - static const PCS &pcs(const GCS &gcs, int proj); + static PCS pcs(int id); + static PCS pcs(const GCS &gcs, int proj); static QList > list(); private: diff --git a/src/map/prjfile.cpp b/src/map/prjfile.cpp index a45eafb9..1f3cf521 100644 --- a/src/map/prjfile.cpp +++ b/src/map/prjfile.cpp @@ -540,9 +540,7 @@ void PRJFile::projectedCS(CTX &ctx, PCS *pcs) optProjectedCS(ctx, &epsg); compare(ctx, RBRK); - *pcs = (epsg > 0) - ? PCS::pcs(epsg) - : PCS(gcs, method, setup, lu, CoordinateSystem()); + *pcs = (epsg > 0) ? PCS::pcs(epsg) : PCS(gcs, method, setup, lu); } void PRJFile::axisType(CTX &ctx) diff --git a/src/map/rmap.cpp b/src/map/rmap.cpp index 878d08f2..335e909f 100644 --- a/src/map/rmap.cpp +++ b/src/map/rmap.cpp @@ -125,7 +125,7 @@ bool RMap::parseIMP(const QByteArray &data) } } - const GCS &gcs = GCS::gcs(datum); + GCS gcs(GCS::gcs(datum)); if (gcs.isNull()) { _errorString = datum + ": unknown/invalid datum"; return false;