From c088c68f53bb26ab01d7883a05f2076a52bb403f Mon Sep 17 00:00:00 2001
From: Thomas Fischer <thomas.fischer@ufz.de>
Date: Fri, 9 Jun 2023 07:53:33 +0200
Subject: [PATCH] [MeL/IO/XDMF/XdmfHdfWriter] Code quality improvements

- Make constant_output_names a local std::array
- Initialize the array with initializer list instead of insert in previous version
---
 MeshLib/IO/XDMF/XdmfHdfWriter.cpp | 37 +++++++++++++++----------------
 1 file changed, 18 insertions(+), 19 deletions(-)

diff --git a/MeshLib/IO/XDMF/XdmfHdfWriter.cpp b/MeshLib/IO/XDMF/XdmfHdfWriter.cpp
index a5ee058ba03..4754c899db4 100644
--- a/MeshLib/IO/XDMF/XdmfHdfWriter.cpp
+++ b/MeshLib/IO/XDMF/XdmfHdfWriter.cpp
@@ -11,6 +11,7 @@
 
 #include <algorithm>
 #include <functional>
+#include <range/v3/algorithm/contains.hpp>
 
 #include "BaseLib/Algorithm.h"
 #include "InfoLib/GitInfo.h"
@@ -39,13 +40,22 @@ struct XdmfHdfMesh final
 
 template <typename Data>
 std::function<bool(Data)> isVariableAttribute(
-    std::set<std::string> const& variable_output_names,
-    std::set<std::string> const& constant_output_names)
+    std::set<std::string> const& variable_output_names)
 {
     if (variable_output_names.empty())
     {
-        return [&constant_output_names](Data const& data) -> bool
-        { return !constant_output_names.contains(data.name); };
+        return [](Data const& data) -> bool
+        {
+            constexpr std::array constant_output_names{
+                "MaterialIDs"sv,
+                "topology"sv,
+                "geometry"sv,
+                MeshLib::getBulkIDString(MeshLib::MeshItemType::Node),
+                MeshLib::getBulkIDString(MeshLib::MeshItemType::Cell),
+                MeshLib::getBulkIDString(MeshLib::MeshItemType::Edge),
+                MeshLib::getBulkIDString(MeshLib::MeshItemType::Face)};
+            return !ranges::contains(constant_output_names, data.name);
+        };
     }
     return [&variable_output_names](Data const& data) -> bool
     { return variable_output_names.contains(data.name); };
@@ -61,17 +71,6 @@ XdmfHdfWriter::XdmfHdfWriter(
     // ogs meshes to vector of Xdmf/HDF meshes (we keep Xdmf and HDF together
     // because XDMF depends on HDF) to meta
 
-    std::set<std::string> constant_output_names;
-    for (std::string_view item :
-         {"MaterialIDs"sv, "topology"sv, "geometry"sv,
-          MeshLib::getBulkIDString(MeshLib::MeshItemType::Node),
-          MeshLib::getBulkIDString(MeshLib::MeshItemType::Cell),
-          MeshLib::getBulkIDString(MeshLib::MeshItemType::Edge),
-          MeshLib::getBulkIDString(MeshLib::MeshItemType::Face)})
-    {
-        constant_output_names.insert(std::string(item));
-    };
-
     // if no output name is specified, all data will be assumened to be
     // variable over the timesteps. The xdmfhdfwriter is an alternative to
     // other writers, that do not consider the constantness of data Callers
@@ -113,8 +112,8 @@ XdmfHdfWriter::XdmfHdfWriter(
                            std::move(attributes), mesh.get().getName(),
                            std::move(xdmf_conforming_data)};
     };
-    auto isVariableHdfAttribute = isVariableAttribute<HdfData>(
-        variable_output_names, constant_output_names);
+    auto isVariableHdfAttribute =
+        isVariableAttribute<HdfData>(variable_output_names);
 
     // extract meta data relevant for HDFWriter
     auto const transform_metamesh_to_hdf =
@@ -172,8 +171,8 @@ XdmfHdfWriter::XdmfHdfWriter(
         return;
     }
 
-    auto isVariableXdmfAttribute = isVariableAttribute<XdmfData>(
-        variable_output_names, constant_output_names);
+    auto isVariableXdmfAttribute =
+        isVariableAttribute<XdmfData>(variable_output_names);
     // xdmf section
     // extract meta data relevant for XDMFWriter
     auto const transform_metamesh_to_xdmf =
-- 
GitLab