From 54ab3ff1d9697e2aa9f4b88e128a9f339846696d Mon Sep 17 00:00:00 2001 From: Jaswant Panchumarti <jaswant.panchumarti@kitware.com> Date: Sat, 15 Feb 2025 19:48:32 -0500 Subject: [PATCH] vtkCellGrid: Move definitions of non-templated functions to CXX file - This commit refactors the code to resolve `-Wunique-object-duplication`. - While in here, also moves the implementation of the other non templated `std::vector<std::string> vtkCellGrid::GetCellTypes()` function to `vtkCellGrid.cxx` for consistency. --- Common/DataModel/vtkCellGrid.cxx | 28 ++++++++++++++++++++++++++++ Common/DataModel/vtkCellGrid.h | 28 ++-------------------------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/Common/DataModel/vtkCellGrid.cxx b/Common/DataModel/vtkCellGrid.cxx index 72672181d97..12f3c281990 100644 --- a/Common/DataModel/vtkCellGrid.cxx +++ b/Common/DataModel/vtkCellGrid.cxx @@ -422,6 +422,34 @@ int vtkCellGrid::RemoveUnusedCellMetadata() return numRemoved; } +std::vector<vtkStringToken> vtkCellGrid::CellTypeArray() const +{ +#if defined(_MSC_VER) && _MSC_VER >= 1930 && _MSC_VER < 1940 /*17.4+*/ + // MSVC 2022 shows LNK1161 when an exported method uses thread_local in its implementation. + // See https://github.com/pytorch/pytorch/issues/87957 for more. We omit the + // thread_local here, which makes this method non-threadsafe on Windows, which + // should be OK in most cases. + static std::vector<vtkStringToken> cellTypes; +#else + static thread_local std::vector<vtkStringToken> cellTypes; +#endif + cellTypes.clear(); + this->CellTypes(cellTypes); + return cellTypes; +} + +std::vector<std::string> vtkCellGrid::GetCellTypes() const +{ + auto cta = this->CellTypeArray(); + std::vector<std::string> result; + result.reserve(cta.size()); + for (const auto& cellTypeToken : cta) + { + result.push_back(cellTypeToken.Data()); + } + return result; +} + const vtkCellMetadata* vtkCellGrid::GetCellType(vtkStringToken cellTypeName) const { auto it = this->Cells.find(cellTypeName); diff --git a/Common/DataModel/vtkCellGrid.h b/Common/DataModel/vtkCellGrid.h index be27f8a98d5..65b8f159644 100644 --- a/Common/DataModel/vtkCellGrid.h +++ b/Common/DataModel/vtkCellGrid.h @@ -282,32 +282,8 @@ public: this->CellTypes(cellTypes); return cellTypes; } - std::vector<vtkStringToken> CellTypeArray() const - { -#if defined(_MSC_VER) && _MSC_VER >= 1930 && _MSC_VER < 1940 /*17.4+*/ - // MSVC 2022 bombs when an exported method uses thread_local in its implementation. - // See https://github.com/pytorch/pytorch/issues/87957 for more. We omit the - // thread_local here, which makes this method non-threadsafe on Windows, which - // should be OK in most cases. - static std::vector<vtkStringToken> cellTypes; -#else - static thread_local std::vector<vtkStringToken> cellTypes; -#endif - cellTypes.clear(); - this->CellTypes(cellTypes); - return cellTypes; - } - std::vector<std::string> GetCellTypes() const - { - auto cta = this->CellTypeArray(); - std::vector<std::string> result; - result.reserve(cta.size()); - for (const auto& cellTypeToken : cta) - { - result.push_back(cellTypeToken.Data()); - } - return result; - } + std::vector<vtkStringToken> CellTypeArray() const; + std::vector<std::string> GetCellTypes() const; ///@} ///@{ -- GitLab