From 8d786107bd0bf756674319dfc357f121873d9e76 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sun, 7 Mar 2021 00:30:19 +0100 Subject: insertIntoHierarchy(): avoid confusing cppcheck about potential use of moved grid --- src/grids.cpp | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) (limited to 'src/grids.cpp') diff --git a/src/grids.cpp b/src/grids.cpp index ce0f6b76..3bde3cad 100644 --- a/src/grids.cpp +++ b/src/grids.cpp @@ -1140,7 +1140,7 @@ insertIntoHierarchy(PJ_CONTEXT *ctx, std::unique_ptr &&grid, } mapGrids[gridName] = grid.get(); } - bool gridInserted = false; + if (!parentName.empty()) { auto iter = mapGrids.find(parentName); if (iter == mapGrids.end()) { @@ -1151,7 +1151,7 @@ insertIntoHierarchy(PJ_CONTEXT *ctx, std::unique_ptr &&grid, } else { if (iter->second->extentAndRes().contains(extent)) { iter->second->m_children.emplace_back(std::move(grid)); - gridInserted = true; + return; } else { pj_log(ctx, PJ_LOG_DEBUG, "Grid %s refers to parent %s, but its extent is " @@ -1161,27 +1161,22 @@ insertIntoHierarchy(PJ_CONTEXT *ctx, std::unique_ptr &&grid, } } else if (!gridName.empty()) { topGrids.emplace_back(std::move(grid)); - gridInserted = true; + return; } // Fallback to analyzing spatial extents - if (!gridInserted) { - for (const auto &candidateParent : topGrids) { - const auto &candidateParentExtent = candidateParent->extentAndRes(); - if (candidateParentExtent.contains(extent)) { - static_cast(candidateParent.get()) - ->insertGrid(ctx, std::move(grid)); - gridInserted = true; - break; - } else if (candidateParentExtent.intersects(extent)) { - pj_log(ctx, PJ_LOG_DEBUG, - "Partially intersecting grids found!"); - } - } - if (!gridInserted) { - topGrids.emplace_back(std::move(grid)); + for (const auto &candidateParent : topGrids) { + const auto &candidateParentExtent = candidateParent->extentAndRes(); + if (candidateParentExtent.contains(extent)) { + static_cast(candidateParent.get()) + ->insertGrid(ctx, std::move(grid)); + return; + } else if (candidateParentExtent.intersects(extent)) { + pj_log(ctx, PJ_LOG_DEBUG, "Partially intersecting grids found!"); } } + + topGrids.emplace_back(std::move(grid)); } #ifdef TIFF_ENABLED -- cgit v1.2.3