From 252067479a736291497f4be95221ac69f645b671 Mon Sep 17 00:00:00 2001 From: tomc271 Date: Wed, 8 Jul 2026 14:58:32 +0100 Subject: [PATCH 1/3] Refactor map::find expression: lookup and retrieval in a single step with C++17 initializer syntax --- src/field/field_data.cxx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/field/field_data.cxx b/src/field/field_data.cxx index 8f6a808482..b54f95ba64 100644 --- a/src/field/field_data.cxx +++ b/src/field/field_data.cxx @@ -189,12 +189,11 @@ void FieldData::addBndryGenerator(FieldGeneratorPtr gen, BndryLoc location) { } FieldGeneratorPtr FieldData::getBndryGenerator(BndryLoc location) { - auto it = bndry_generator.find(location); - if (it == bndry_generator.end()) { - return nullptr; + if (const auto it = bndry_generator.find(location); it != bndry_generator.end()) { + return it->second; } - return it->second; + return nullptr; } Mesh* FieldData::getMesh() const { From 28542c95c77314ba4ceca1e839a84f41dc700d4e Mon Sep 17 00:00:00 2001 From: tomc271 Date: Wed, 8 Jul 2026 15:17:19 +0100 Subject: [PATCH 2/3] Lookup and retrieval in a single step with C++17 initializer syntax --- src/field/field_factory.cxx | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/field/field_factory.cxx b/src/field/field_factory.cxx index 1f5984ba48..220597a215 100644 --- a/src/field/field_factory.cxx +++ b/src/field/field_factory.cxx @@ -301,8 +301,7 @@ Field3D FieldFactory::create3D(FieldGeneratorPtr gen, Mesh* localmesh, CELL_LOC }; if (transform_from_field_aligned) { - auto coords = result.getCoordinates(); - if (coords == nullptr) { + if (auto coords = result.getCoordinates(); coords == nullptr) { // Should not lead to issues. If called from the coordinates // constructor, then this is expected, and the result will be // transformed. Otherwise, if the field is used untransformed, @@ -352,8 +351,7 @@ FieldPerp FieldFactory::createPerp(FieldGeneratorPtr gen, Mesh* localmesh, CELL_ }; if (transform_from_field_aligned) { - auto coords = result.getCoordinates(); - if (coords == nullptr) { + if (auto coords = result.getCoordinates(); coords == nullptr) { // Should not lead to issues. If called from the coordinates // constructor, then this is expected, and the result will be // transformed. Otherwise, if the field is used untransformed, @@ -376,8 +374,7 @@ const Options* FieldFactory::findOption(const Options* opt, const std::string& n const Options* result = opt; // Check if name contains a section separator ':' - size_t pos = name.find(':'); - if (pos == std::string::npos) { + if (auto pos = name.find(':'); pos == std::string::npos) { // No separator. Try this section, and then go through parents while (!result->isSet(name)) { @@ -517,8 +514,7 @@ FieldGeneratorPtr FieldFactory::parse(const std::string& input, key = opt->str() + key; // Include options context in key } - auto it = cache.find(key); - if (it != cache.end()) { + if (auto it = cache.find(key); it != cache.end()) { return it->second; } From a56a9960117e0bc1d06cdcee748e100446611b04 Mon Sep 17 00:00:00 2001 From: tomc271 Date: Wed, 8 Jul 2026 13:27:25 +0100 Subject: [PATCH 3/3] Move variable 'search' to if-init-statement --- src/mesh/coordinates_accessor.cxx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/mesh/coordinates_accessor.cxx b/src/mesh/coordinates_accessor.cxx index efc27e9715..6967087a0e 100644 --- a/src/mesh/coordinates_accessor.cxx +++ b/src/mesh/coordinates_accessor.cxx @@ -21,8 +21,7 @@ CoordinatesAccessor::CoordinatesAccessor(const Coordinates* coords) { Mesh* mesh = coords->dx.getMesh(); mesh_nz = mesh->LocalNz; - auto search = coords_store.find(coords); - if (search != coords_store.end()) { + if (const auto search = coords_store.find(coords); search != coords_store.end()) { // Found, so get the pointer to the data data = search->second.begin(); return;