Skip to content

Commit

Permalink
Fix Coverity performance inefficiencies warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Jan 14, 2024
1 parent 1a4e78e commit 0bf4ede
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/iso19111/c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 9 additions & 5 deletions src/iso19111/crs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,8 @@ CRSNNPtr CRS::promoteTo3D(const std::string &newName,
std::string(), dbContext, verticalAxisIfNotAlreadyPresent));
return util::nn_static_pointer_cast<CRS>(
DerivedGeographicCRS::create(
createProperties(), NN_CHECK_THROW(baseGeog3DCRS),
createProperties(),
NN_CHECK_THROW(std::move(baseGeog3DCRS)),
derivedGeogCRS->derivingConversion(), std::move(cs)));
}
}
Expand All @@ -1373,7 +1374,8 @@ CRSNNPtr CRS::promoteTo3D(const std::string &newName,
std::string(), dbContext, verticalAxisIfNotAlreadyPresent));
return util::nn_static_pointer_cast<CRS>(
DerivedProjectedCRS::create(
createProperties(), NN_CHECK_THROW(baseProj3DCRS),
createProperties(),
NN_CHECK_THROW(std::move(baseProj3DCRS)),
derivedProjCRS->derivingConversion(), std::move(cs)));
}
}
Expand Down Expand Up @@ -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<datum::EllipsoidNNPtr> ellipsoids(
thisEllipsoid->identifiers().empty()
? authorityFactory->createEllipsoidFromExisting(
thisEllipsoid)
Expand Down Expand Up @@ -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<DerivedGeographicCRS>(
Expand Down Expand Up @@ -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<DerivedProjectedCRS>(
Expand Down
2 changes: 1 addition & 1 deletion src/iso19111/datum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions src/iso19111/factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2208,7 +2208,7 @@ std::vector<std::string> DatabaseContext::Private::getInsertStatementsFor(
frameReferenceEpoch =
toString(dynamicDatum->frameReferenceEpoch().value());
}
const std::string anchor = *(datum->anchorDefinition());
const std::string anchor(*(datum->anchorDefinition()));
const util::optional<common::Measure> &anchorEpoch = datum->anchorEpoch();
const auto sql = formatStatement(
"INSERT INTO geodetic_datum VALUES("
Expand Down Expand Up @@ -2303,7 +2303,7 @@ std::vector<std::string> 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<common::Measure> &anchorEpoch =
firstDatum->anchorEpoch();
const auto sql = formatStatement(
Expand All @@ -2324,7 +2324,7 @@ std::vector<std::string> 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<common::Measure> &anchorEpoch =
firstDatum->anchorEpoch();
const auto sql = formatStatement(
Expand Down Expand Up @@ -2683,7 +2683,7 @@ std::vector<std::string> DatabaseContext::Private::getInsertStatementsFor(
frameReferenceEpoch =
toString(dynamicDatum->frameReferenceEpoch().value());
}
const auto anchor = *(datum->anchorDefinition());
const std::string anchor(*(datum->anchorDefinition()));
const util::optional<common::Measure> &anchorEpoch = datum->anchorEpoch();
const auto sql = formatStatement(
"INSERT INTO vertical_datum VALUES("
Expand Down
16 changes: 8 additions & 8 deletions src/iso19111/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -9770,11 +9770,11 @@ PROJStringSyntaxParser(const std::string &projString, std::vector<Step> &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()) {
Expand Down Expand Up @@ -9833,13 +9833,13 @@ PROJStringSyntaxParser(const std::string &projString, std::vector<Step> &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));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/iso19111/operation/singleoperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {

Expand Down
2 changes: 1 addition & 1 deletion src/iso19111/operation/transformation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 0bf4ede

Please sign in to comment.