From 15714871713c65ea11080016323339c51731a8d7 Mon Sep 17 00:00:00 2001 From: Martin Kronbichler Date: Thu, 13 Aug 2020 12:49:51 +0200 Subject: [PATCH] Improve performance of ReferenceCell::Info::get_cell --- include/deal.II/grid/reference_cell.h | 46 ++++++++------------------- 1 file changed, 13 insertions(+), 33 deletions(-) diff --git a/include/deal.II/grid/reference_cell.h b/include/deal.II/grid/reference_cell.h index a17be580e2..98cf416d3c 100644 --- a/include/deal.II/grid/reference_cell.h +++ b/include/deal.II/grid/reference_cell.h @@ -1000,43 +1000,23 @@ namespace ReferenceCell }; /** - * Return for a given reference-cell type @p the right Info. + * Return for a given reference-cell type the right Info. */ inline const ReferenceCell::internal::Info::Base & get_cell(const ReferenceCell::Type &type) { - static ReferenceCell::internal::Info::Base gei_invalid; - static ReferenceCell::internal::Info::Vertex gei_vertex; - static ReferenceCell::internal::Info::Line gei_line; - static ReferenceCell::internal::Info::Tri gei_tri; - static ReferenceCell::internal::Info::Quad gei_quad; - static ReferenceCell::internal::Info::Tet gei_tet; - static ReferenceCell::internal::Info::Pyramid gei_pyramid; - static ReferenceCell::internal::Info::Wedge gei_wedge; - static ReferenceCell::internal::Info::Hex gei_hex; - - switch (type) - { - case ReferenceCell::Type::Vertex: - return gei_vertex; - case ReferenceCell::Type::Line: - return gei_line; - case ReferenceCell::Type::Tri: - return gei_tri; - case ReferenceCell::Type::Quad: - return gei_quad; - case ReferenceCell::Type::Tet: - return gei_tet; - case ReferenceCell::Type::Pyramid: - return gei_pyramid; - case ReferenceCell::Type::Wedge: - return gei_wedge; - case ReferenceCell::Type::Hex: - return gei_hex; - default: - Assert(false, StandardExceptions::ExcNotImplemented()); - return gei_invalid; - } + static const std:: + array, 8> + gei{{std::make_unique(), + std::make_unique(), + std::make_unique(), + std::make_unique(), + std::make_unique(), + std::make_unique(), + std::make_unique(), + std::make_unique()}}; + AssertIndexRange(static_cast(type), 8); + return *gei[static_cast(type)]; } /** -- 2.39.5