From a2a58f9dfaf88d31f3b32eacaea7be9255fe1a28 Mon Sep 17 00:00:00 2001 From: Martin Kronbichler Date: Sat, 9 Jan 2016 20:57:39 +0100 Subject: [PATCH] Avoid initializing memory twice for non-trivial classes in table constructor. --- include/deal.II/base/table.h | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/include/deal.II/base/table.h b/include/deal.II/base/table.h index 54c8f804d6..40646674db 100644 --- a/include/deal.II/base/table.h +++ b/include/deal.II/base/table.h @@ -1902,11 +1902,24 @@ TableBase::reinit (const TableIndices &new_sizes, return; } - // if new size is nonzero: if necessary allocate additional memory, and if - // not fast resize, zero out all values/default initialize them) - values.resize_fast (new_size); + // adjust values field. If it was empty before, we can simply call resize(), + // which can set all the data fields. Otherwise, select the fast resize and + // manually fill in all the elements as required by the design of this + // class. (Selecting another code for the empty case ensures that we touch + // the memory only once for non-trivial classes that need to initialize the + // memory also in resize_fast.) if (!omit_default_initialization) - values.fill(T()); + { + if (values.empty()) + values.resize(new_size, T()); + else + { + values.resize_fast(new_size); + values.fill(T()); + } + } + else + values.resize_fast (new_size); } -- 2.39.5