Skip to content

Commit

Permalink
Merge pull request #3233 from rouault/optim_isequivalent_to
Browse files Browse the repository at this point in the history
IComparable::isEquivalentTo() optimizations
  • Loading branch information
rouault committed Jun 19, 2022
2 parents 019dad3 + b241fbb commit 7a75798
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
45 changes: 20 additions & 25 deletions src/iso19111/crs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1497,33 +1497,28 @@ bool SingleCRS::baseIsEquivalentTo(
}

// Check datum
if (criterion == util::IComparable::Criterion::STRICT) {
const auto &thisDatum = d->datum;
const auto &otherDatum = otherSingleCRS->d->datum;
if (thisDatum) {
if (otherDatum == nullptr ||
!thisDatum->_isEquivalentTo(otherDatum.get(), criterion,
dbContext)) {
return false;
}
} else {
if (otherDatum) {
return false;
}
const auto &thisDatum = d->datum;
const auto &otherDatum = otherSingleCRS->d->datum;
const auto &thisDatumEnsemble = d->datumEnsemble;
const auto &otherDatumEnsemble = otherSingleCRS->d->datumEnsemble;
if (thisDatum && otherDatum) {
if (!thisDatum->_isEquivalentTo(otherDatum.get(), criterion,
dbContext)) {
return false;
}
} else if (thisDatumEnsemble && otherDatumEnsemble) {
if (!thisDatumEnsemble->_isEquivalentTo(otherDatumEnsemble.get(),
criterion, dbContext)) {
return false;
}
}

const auto &thisDatumEnsemble = d->datumEnsemble;
const auto &otherDatumEnsemble = otherSingleCRS->d->datumEnsemble;
if (thisDatumEnsemble) {
if (otherDatumEnsemble == nullptr ||
!thisDatumEnsemble->_isEquivalentTo(otherDatumEnsemble.get(),
criterion, dbContext)) {
return false;
}
} else {
if (otherDatumEnsemble) {
return false;
}
if (criterion == util::IComparable::Criterion::STRICT) {
if ((thisDatum != nullptr) ^ (otherDatum != nullptr)) {
return false;
}
if ((thisDatumEnsemble != nullptr) ^ (otherDatumEnsemble != nullptr)) {
return false;
}
} else {
if (!datumNonNull(dbContext)->_isEquivalentTo(
Expand Down
2 changes: 2 additions & 0 deletions src/iso19111/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,8 @@ IComparable::~IComparable() = default;
bool IComparable::isEquivalentTo(
const IComparable *other, Criterion criterion,
const io::DatabaseContextPtr &dbContext) const {
if (this == other)
return true;
return _isEquivalentTo(other, criterion, dbContext);
}

Expand Down

0 comments on commit 7a75798

Please sign in to comment.