From: Martin Kronbichler Date: Sat, 9 Jan 2016 19:57:39 +0000 (+0100) Subject: Avoid initializing memory twice for non-trivial classes in table constructor. X-Git-Tag: v8.4.0-rc2~103^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a2a58f9dfaf88d31f3b32eacaea7be9255fe1a28;p=dealii.git Avoid initializing memory twice for non-trivial classes in table constructor. --- 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); }