Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Coverity performance inefficiencies warnings #4002

Merged
merged 2 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions src/4D_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2347,18 +2347,15 @@ PJ *proj_create_crs_to_crs_from_pj(PJ_CONTEXT *ctx, const PJ *source_crs,
// PROJ_GRID_AVAILABILITY_DISCARD_OPERATION_IF_MISSING_GRID
// returned 0.
if (op_count == 1 &&
(errorIfBestTransformationNotAvailable ||
warnIfBestTransformationNotAvailable)) {
errorIfBestTransformationNotAvailable) {
jjimenezshaw marked this conversation as resolved.
Show resolved Hide resolved
if (singleOpIsInstanciable < 0) {
singleOpIsInstanciable =
proj_coordoperation_is_instantiable(ctx, P);
}
if (!singleOpIsInstanciable) {
if (errorIfBestTransformationNotAvailable) {
proj_destroy(P);
proj_context_errno_set(ctx, backup_errno);
return nullptr;
}
proj_destroy(P);
proj_context_errno_set(ctx, backup_errno);
return nullptr;
}
}
}
Expand Down
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
Loading