Skip to content

Commit

Permalink
Refactor: avoid local variable only used in range-based for loops
Browse files Browse the repository at this point in the history
  • Loading branch information
kriben committed Apr 4, 2024
1 parent 94ea0dd commit cdb2108
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 68 deletions.
3 changes: 1 addition & 2 deletions ApplicationLibCode/Application/RiaApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,8 +690,7 @@ bool RiaApplication::loadProject( const QString& projectFileName, ProjectLoadAct
}

{
std::vector<Rim3dView*> views = m_project->allViews();
for ( auto view : views )
for ( auto view : m_project->allViews() )
{
if ( auto eclipseView = dynamic_cast<RimEclipseView*>( view ) )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ void RicNewValveTemplateFeature::selectValveTemplateAndUpdate( RimValveTemplate*

RimProject* project = RimProject::current();

std::vector<Rim3dView*> views = project->allVisibleViews();
for ( Rim3dView* view : views )
for ( Rim3dView* view : project->allVisibleViews() )
{
if ( dynamic_cast<RimEclipseView*>( view ) )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,8 @@ caf::PdmScriptResponse RicExportContourMapToTextFeature::execute()
RimProject* proj = app->project();
CAF_ASSERT( proj );

std::vector<Rim3dView*> allViews = proj->allViews();
Rim3dView* myView = nullptr;
for ( auto view : allViews )
Rim3dView* myView = nullptr;
for ( auto view : proj->allViews() )
{
if ( m_viewId == view->id() )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ void RicWellMeasurementImportTools::importWellMeasurementsFromFiles( const QStri
auto proj = RimProject::current();
if ( proj )
{
std::vector<Rim3dView*> views = proj->allViews();
for ( auto& view : views )
for ( auto& view : proj->allViews() )
{
RimGridView* gridView = dynamic_cast<RimGridView*>( view );
if ( gridView )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ RimSeismicView* RicNewSeismicViewFeature::createInitialViewIfNeeded( RimSeismicD
{
auto proj = RimProject::current();

std::vector<Rim3dView*> views = proj->allViews();
if ( !views.empty() ) return nullptr;
if ( !proj->allViews().empty() ) return nullptr;

return createSeismicView( seisData );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ std::vector<Rim3dView*> RicLinkVisibleViewsFeature::findLinkableVisibleViews()
RimProject* proj = RimProject::current();

std::vector<Rim3dView*> views;

std::vector<Rim3dView*> candidates = proj->allVisibleViews();
for ( auto gridView : candidates )
for ( auto gridView : proj->allVisibleViews() )
{
if ( gridView && !gridView->assosiatedViewLinker() ) views.push_back( gridView );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,7 @@ void RimFractureTemplateCollection::onChildDeleted( caf::PdmChildArrayFieldHandl
proj->scheduleCreateDisplayModelAndRedrawAllViews();
}

std::vector<Rim3dView*> views = proj->allVisibleViews();
for ( Rim3dView* visibleView : views )
for ( Rim3dView* visibleView : proj->allVisibleViews() )
{
if ( dynamic_cast<RimEclipseView*>( visibleView ) )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,7 @@ void RimPolygonCollection::updateViewTreeItems()
RimProject* proj = RimProject::current();

// Make sure the tree items are synchronized
std::vector<Rim3dView*> views = proj->allViews();
for ( auto view : views )
for ( auto view : proj->allViews() )
{
view->updateViewTreeItems( RiaDefines::ItemIn3dView::POLYGON );
}
Expand Down
7 changes: 2 additions & 5 deletions ApplicationLibCode/ProjectDataModel/Rim3dView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ Rim3dView::~Rim3dView()

if ( auto proj = RimProject::current() )
{
std::vector<Rim3dView*> allViews = proj->allViews();
for ( auto v : allViews )
for ( auto v : proj->allViews() )
{
if ( v->activeComparisonView() == this )
{
Expand Down Expand Up @@ -589,10 +588,8 @@ std::vector<Rim3dView*> Rim3dView::validComparisonViews() const
{
auto isIntersectionView = []( const Rim3dView* view ) { return dynamic_cast<const Rim2dIntersectionView*>( view ) != nullptr; };

std::vector<Rim3dView*> views = RimProject::current()->allViews();

std::vector<Rim3dView*> validComparisonViews;
for ( auto view : views )
for ( auto view : RimProject::current()->allViews() )
{
if ( dynamic_cast<RimSeismicView*>( view ) ) continue;

Expand Down
55 changes: 17 additions & 38 deletions ApplicationLibCode/ProjectDataModel/RimProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,7 @@ void RimProject::assignCaseIdToSummaryCase( RimSummaryCase* summaryCase )
{
if ( summaryCase )
{
std::vector<RimSummaryCase*> summaryCases = allSummaryCases();
for ( RimSummaryCase* s : summaryCases )
for ( RimSummaryCase* s : allSummaryCases() )
{
m_nextValidSummaryCaseId = std::max( m_nextValidSummaryCaseId, s->caseId() + 1 );
}
Expand All @@ -531,8 +530,7 @@ void RimProject::assignIdToEnsemble( RimSummaryCaseCollection* summaryCaseCollec
{
if ( summaryCaseCollection )
{
std::vector<RimSummaryCaseCollection*> summaryGroups = RimProject::summaryGroups();
for ( RimSummaryCaseCollection* s : summaryGroups )
for ( RimSummaryCaseCollection* s : RimProject::summaryGroups() )
{
m_nextValidEnsembleId = std::max( m_nextValidEnsembleId, s->ensembleId() + 1 );
}
Expand Down Expand Up @@ -745,13 +743,11 @@ std::vector<Rim3dView*> RimProject::allNotLinkedViews() const

std::vector<Rim3dView*> views;

std::vector<RimCase*> cases = allGridCases();
for ( RimCase* rimCase : cases )
for ( RimCase* rimCase : allGridCases() )
{
if ( !rimCase ) continue;

std::vector<Rim3dView*> caseViews = rimCase->views();
for ( Rim3dView* caseView : caseViews )
for ( Rim3dView* caseView : rimCase->views() )
{
RimGridView* gridView = dynamic_cast<RimGridView*>( caseView );

Expand Down Expand Up @@ -782,13 +778,11 @@ std::vector<Rim3dView*> RimProject::allViews() const
{
std::vector<Rim3dView*> views;

std::vector<RimCase*> cases = allGridCases();
for ( RimCase* rimCase : cases )
for ( RimCase* rimCase : allGridCases() )
{
if ( !rimCase ) continue;

std::vector<Rim3dView*> caseViews = rimCase->views();
for ( Rim3dView* view : caseViews )
for ( Rim3dView* view : rimCase->views() )
{
if ( view )
{
Expand Down Expand Up @@ -817,14 +811,11 @@ std::vector<Rim3dView*> RimProject::allViews() const
std::vector<Rim3dView*> RimProject::allVisibleViews() const
{
std::vector<Rim3dView*> views;

std::vector<RimCase*> cases = allGridCases();
for ( RimCase* rimCase : cases )
for ( RimCase* rimCase : allGridCases() )
{
if ( !rimCase ) continue;

std::vector<Rim3dView*> caseViews = rimCase->views();
for ( Rim3dView* view : caseViews )
for ( Rim3dView* view : rimCase->views() )
{
if ( view && view->viewer() )
{
Expand All @@ -842,8 +833,7 @@ std::vector<Rim3dView*> RimProject::allVisibleViews() const
std::vector<RimGridView*> RimProject::allVisibleGridViews() const
{
std::vector<RimGridView*> views;
std::vector<Rim3dView*> visibleViews = allVisibleViews();
for ( Rim3dView* view : visibleViews )
for ( Rim3dView* view : allVisibleViews() )
{
RimGridView* gridView = dynamic_cast<RimGridView*>( view );
if ( gridView ) views.push_back( gridView );
Expand All @@ -857,12 +847,10 @@ std::vector<RimGridView*> RimProject::allVisibleGridViews() const
//--------------------------------------------------------------------------------------------------
void RimProject::scheduleCreateDisplayModelAndRedrawAllViews()
{
std::vector<RimCase*> cases = allGridCases();
for ( RimCase* rimCase : cases )
for ( RimCase* rimCase : allGridCases() )
{
if ( !rimCase ) continue;
std::vector<Rim3dView*> views = rimCase->views();
for ( Rim3dView* view : views )
for ( Rim3dView* view : rimCase->views() )
{
view->scheduleCreateDisplayModelAndRedraw();
}
Expand Down Expand Up @@ -913,11 +901,8 @@ const RimOilField* RimProject::activeOilField() const
//--------------------------------------------------------------------------------------------------
void RimProject::computeUtmAreaOfInterest()
{
std::vector<RimCase*> cases = allGridCases();

cvf::BoundingBox projectBB;

for ( RimCase* rimCase : cases )
for ( RimCase* rimCase : allGridCases() )
{
RimEclipseCase* eclipseCase = dynamic_cast<RimEclipseCase*>( rimCase );
if ( eclipseCase && eclipseCase->eclipseCaseData() )
Expand Down Expand Up @@ -1173,8 +1158,7 @@ std::vector<RimTextAnnotation*> RimProject::textAnnotations() const
}

// 'Local' text annotations
std::vector<RimGridView*> visibleViews = allVisibleGridViews();
for ( const auto& view : visibleViews )
for ( const auto& view : allVisibleGridViews() )
{
std::vector<RimAnnotationInViewCollection*> annotationColls = view->descendantsIncludingThisOfType<RimAnnotationInViewCollection>();

Expand Down Expand Up @@ -1314,11 +1298,9 @@ std::vector<RimValveTemplate*> RimProject::allValveTemplates() const
//--------------------------------------------------------------------------------------------------
caf::AppEnum<RiaDefines::EclipseUnitSystem> RimProject::commonUnitSystemForAllCases() const
{
std::vector<RimCase*> rimCases = allGridCases();

RiaDefines::EclipseUnitSystem commonUnitSystem = RiaDefines::EclipseUnitSystem::UNITS_UNKNOWN;

for ( const auto& c : rimCases )
for ( const auto& c : allGridCases() )
{
auto eclipseCase = dynamic_cast<RimEclipseCase*>( c );
if ( eclipseCase && eclipseCase->eclipseCaseData() )
Expand Down Expand Up @@ -1370,8 +1352,7 @@ std::vector<caf::FilePath*> RimProject::allFilePaths() const
//--------------------------------------------------------------------------------------------------
void RimProject::reloadCompletionTypeResultsForEclipseCase( RimEclipseCase* eclipseCase )
{
std::vector<Rim3dView*> views = eclipseCase->views();
for ( Rim3dView* view : views )
for ( Rim3dView* view : eclipseCase->views() )
{
view->scheduleCreateDisplayModelAndRedraw();
}
Expand Down Expand Up @@ -1537,8 +1518,7 @@ void RimProject::transferPathsToGlobalPathList()
{
RiaVariableMapper variableMapper( m_globalPathList() );

std::vector<caf::FilePath*> filePaths = allFilePaths();
for ( caf::FilePath* filePath : filePaths )
for ( caf::FilePath* filePath : allFilePaths() )
{
QString path = filePath->path();
if ( !path.isEmpty() )
Expand Down Expand Up @@ -1602,8 +1582,7 @@ void RimProject::distributePathsFromGlobalPathList()
{
RiaVariableMapper pathListMapper( m_globalPathList() );

std::vector<caf::FilePath*> filePaths = allFilePaths();
for ( caf::FilePath* filePath : filePaths )
for ( caf::FilePath* filePath : allFilePaths() )
{
QString pathIdCandidate = filePath->path().trimmed();
QStringList pathIdComponents = pathIdCandidate.split( RiaVariableMapper::variableToken() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,7 @@ void RimSurfaceCollection::updateViews( const std::vector<RimSurface*>& surfsToR
RimProject* proj = RimProject::current();

// Make sure the tree items are synchronized
std::vector<Rim3dView*> views = proj->allViews();
for ( auto view : views )
for ( auto view : proj->allViews() )
{
view->updateViewTreeItems( RiaDefines::ItemIn3dView::SURFACE );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,10 @@ void RiuSelectionChangedHandler::scheduleUpdateForAllVisibleViews() const
RimProject* proj = RimProject::current();
if ( proj )
{
std::vector<Rim3dView*> visibleViews = proj->allVisibleViews();

for ( size_t i = 0; i < visibleViews.size(); i++ )
for ( Rim3dView* visibleView : proj->allVisibleViews() )
{
visibleViews[i]->createHighlightAndGridBoxDisplayModelAndRedraw();
visibleViews[i]->createMeasurementDisplayModelAndRedraw();
visibleView->createHighlightAndGridBoxDisplayModelAndRedraw();
visibleView->createMeasurementDisplayModelAndRedraw();
}
}
}
Expand Down

0 comments on commit cdb2108

Please sign in to comment.