From 0bf4edea44d1349d1e2fae031ae76e7b53f16e37 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sun, 14 Jan 2024 19:36:16 +0100 Subject: [PATCH] Fix Coverity performance inefficiencies warnings --- src/iso19111/c_api.cpp | 2 +- src/iso19111/crs.cpp | 14 +++++++++----- src/iso19111/datum.cpp | 2 +- src/iso19111/factory.cpp | 8 ++++---- src/iso19111/io.cpp | 16 ++++++++-------- src/iso19111/operation/singleoperation.cpp | 2 +- src/iso19111/operation/transformation.cpp | 2 +- 7 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/iso19111/c_api.cpp b/src/iso19111/c_api.cpp index cc73b8f92d..ad0f59b0c3 100644 --- a/src/iso19111/c_api.cpp +++ b/src/iso19111/c_api.cpp @@ -380,7 +380,7 @@ const char *proj_context_get_database_path(PJ_CONTEXT *ctx) { try { // temporary variable must be used as getDBcontext() might create // ctx->cpp_context - const auto osPath(getDBcontext(ctx)->getPath()); + const std::string osPath(getDBcontext(ctx)->getPath()); ctx->get_cpp_context()->lastDbPath_ = osPath; return ctx->cpp_context->lastDbPath_.c_str(); } catch (const std::exception &e) { diff --git a/src/iso19111/crs.cpp b/src/iso19111/crs.cpp index f391c86fe6..a380404b72 100644 --- a/src/iso19111/crs.cpp +++ b/src/iso19111/crs.cpp @@ -1356,7 +1356,8 @@ CRSNNPtr CRS::promoteTo3D(const std::string &newName, std::string(), dbContext, verticalAxisIfNotAlreadyPresent)); return util::nn_static_pointer_cast( DerivedGeographicCRS::create( - createProperties(), NN_CHECK_THROW(baseGeog3DCRS), + createProperties(), + NN_CHECK_THROW(std::move(baseGeog3DCRS)), derivedGeogCRS->derivingConversion(), std::move(cs))); } } @@ -1373,7 +1374,8 @@ CRSNNPtr CRS::promoteTo3D(const std::string &newName, std::string(), dbContext, verticalAxisIfNotAlreadyPresent)); return util::nn_static_pointer_cast( DerivedProjectedCRS::create( - createProperties(), NN_CHECK_THROW(baseProj3DCRS), + createProperties(), + NN_CHECK_THROW(std::move(baseProj3DCRS)), derivedProjCRS->derivingConversion(), std::move(cs))); } } @@ -2747,7 +2749,7 @@ GeodeticCRS::identify(const io::AuthorityFactoryPtr &authorityFactory) const { &geodetic_crs_type, l_implicitCS, &dbContext]() { const auto &thisEllipsoid = thisDatum->ellipsoid(); - const auto ellipsoids( + const std::list ellipsoids( thisEllipsoid->identifiers().empty() ? authorityFactory->createEllipsoidFromExisting( thisEllipsoid) @@ -6572,7 +6574,8 @@ DerivedGeographicCRSNNPtr DerivedGeographicCRS::demoteTo2D( return DerivedGeographicCRS::create( util::PropertyMap().set(common::IdentifiedObject::NAME_KEY, !newName.empty() ? newName : nameStr()), - NN_CHECK_THROW(baseGeog2DCRS), derivingConversion(), std::move(cs)); + NN_CHECK_THROW(std::move(baseGeog2DCRS)), derivingConversion(), + std::move(cs)); } return NN_NO_CHECK(std::dynamic_pointer_cast( @@ -6687,7 +6690,8 @@ DerivedProjectedCRS::demoteTo2D(const std::string &newName, return DerivedProjectedCRS::create( util::PropertyMap().set(common::IdentifiedObject::NAME_KEY, !newName.empty() ? newName : nameStr()), - NN_CHECK_THROW(baseProj2DCRS), derivingConversion(), std::move(cs)); + NN_CHECK_THROW(std::move(baseProj2DCRS)), derivingConversion(), + std::move(cs)); } return NN_NO_CHECK(std::dynamic_pointer_cast( diff --git a/src/iso19111/datum.cpp b/src/iso19111/datum.cpp index 982eca1644..7a1fb612fb 100644 --- a/src/iso19111/datum.cpp +++ b/src/iso19111/datum.cpp @@ -1360,7 +1360,7 @@ void GeodeticReferenceFrame::_exportToWKT( l_name, "geodetic_datum", "ESRI"); size_t pos; if (!l_alias.empty()) { - l_name = l_alias; + l_name = std::move(l_alias); aliasFound = true; } else if ((pos = l_name.find(" (")) != std::string::npos) { l_alias = dbContext->getAliasFromOfficialName( diff --git a/src/iso19111/factory.cpp b/src/iso19111/factory.cpp index 95c21b788f..0d2f96fbf5 100644 --- a/src/iso19111/factory.cpp +++ b/src/iso19111/factory.cpp @@ -2208,7 +2208,7 @@ std::vector DatabaseContext::Private::getInsertStatementsFor( frameReferenceEpoch = toString(dynamicDatum->frameReferenceEpoch().value()); } - const std::string anchor = *(datum->anchorDefinition()); + const std::string anchor(*(datum->anchorDefinition())); const util::optional &anchorEpoch = datum->anchorEpoch(); const auto sql = formatStatement( "INSERT INTO geodetic_datum VALUES(" @@ -2303,7 +2303,7 @@ std::vector DatabaseContext::Private::getInsertStatementsFor( assert(!pmIds.empty()); const std::string &pmAuthName = *(pmIds.front()->codeSpace()); const std::string &pmCode = pmIds.front()->code(); - const auto anchor = *(firstDatum->anchorDefinition()); + const std::string anchor(*(firstDatum->anchorDefinition())); const util::optional &anchorEpoch = firstDatum->anchorEpoch(); const auto sql = formatStatement( @@ -2324,7 +2324,7 @@ std::vector DatabaseContext::Private::getInsertStatementsFor( const auto firstDatum = AuthorityFactory::create(self, membersId.front().first) ->createVerticalDatum(membersId.front().second); - const auto anchor = *(firstDatum->anchorDefinition()); + const std::string anchor(*(firstDatum->anchorDefinition())); const util::optional &anchorEpoch = firstDatum->anchorEpoch(); const auto sql = formatStatement( @@ -2683,7 +2683,7 @@ std::vector DatabaseContext::Private::getInsertStatementsFor( frameReferenceEpoch = toString(dynamicDatum->frameReferenceEpoch().value()); } - const auto anchor = *(datum->anchorDefinition()); + const std::string anchor(*(datum->anchorDefinition())); const util::optional &anchorEpoch = datum->anchorEpoch(); const auto sql = formatStatement( "INSERT INTO vertical_datum VALUES(" diff --git a/src/iso19111/io.cpp b/src/iso19111/io.cpp index d85b16f601..3d4ed0b7e1 100644 --- a/src/iso19111/io.cpp +++ b/src/iso19111/io.cpp @@ -4207,7 +4207,7 @@ ConversionNNPtr WKTParser::Private::buildProjectionStandard( } } - std::string projectionName(wkt1ProjectionName); + std::string projectionName(std::move(wkt1ProjectionName)); const MethodMapping *mapping = tryToIdentifyWKT1Method ? getMappingFromWKT1(projectionName) : nullptr; @@ -9770,11 +9770,11 @@ PROJStringSyntaxParser(const std::string &projString, std::vector &steps, steps.back().name.empty()) { assert(hasProj); auto stepName = word.substr(strlen("proj=")); - steps.back().name = stepName; + steps.back().name = std::move(stepName); } else if (starts_with(word, "init=")) { assert(hasInit); auto initName = word.substr(strlen("init=")); - steps.back().name = initName; + steps.back().name = std::move(initName); steps.back().isInit = true; } else if (word == "inv") { if (!steps.empty()) { @@ -9833,13 +9833,13 @@ PROJStringSyntaxParser(const std::string &projString, std::vector &steps, } else { const auto pos = word.find('='); auto key = word.substr(0, pos); - auto pair = (pos != std::string::npos) - ? Step::KeyValue(key, word.substr(pos + 1)) - : Step::KeyValue(key); + Step::KeyValue pair((pos != std::string::npos) + ? Step::KeyValue(key, word.substr(pos + 1)) + : Step::KeyValue(key)); if (steps.empty()) { - globalParamValues.push_back(pair); + globalParamValues.emplace_back(std::move(pair)); } else { - steps.back().paramValues.push_back(pair); + steps.back().paramValues.emplace_back(std::move(pair)); } } } diff --git a/src/iso19111/operation/singleoperation.cpp b/src/iso19111/operation/singleoperation.cpp index 24b1b3a80b..4dbd5b2195 100644 --- a/src/iso19111/operation/singleoperation.cpp +++ b/src/iso19111/operation/singleoperation.cpp @@ -2562,7 +2562,7 @@ TransformationNNPtr SingleOperation::substitutePROJAlternativeGridNames( if (fileParameter && fileParameter->type() == ParameterValue::Type::FILENAME) { - auto filename = fileParameter->valueFile(); + const auto &filename = fileParameter->valueFile(); if (databaseContext->lookForGridAlternative( filename, projFilename, projGridFormat, inverseDirection)) { diff --git a/src/iso19111/operation/transformation.cpp b/src/iso19111/operation/transformation.cpp index 52898d8192..f6ce84f27d 100644 --- a/src/iso19111/operation/transformation.cpp +++ b/src/iso19111/operation/transformation.cpp @@ -1628,7 +1628,7 @@ TransformationNNPtr Transformation::inverseAsTransformation() const { } if (methodEPSGCode == EPSG_CODE_METHOD_GEOGRAPHIC2D_WITH_HEIGHT_OFFSETS) { - auto offsetLat = + const auto &offsetLat = parameterValueMeasure(EPSG_CODE_PARAMETER_LATITUDE_OFFSET); const common::Angle newOffsetLat(negate(offsetLat.value()), offsetLat.unit());