From: bangerth Date: Wed, 10 Mar 2010 00:46:59 +0000 (+0000) Subject: Initialize a local variable and general cleanup. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bfb624c3eb8b839523b49553492e6cf236778392;p=dealii-svn.git Initialize a local variable and general cleanup. git-svn-id: https://svn.dealii.org/trunk@20779 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/lac/include/lac/constraint_matrix.templates.h b/deal.II/lac/include/lac/constraint_matrix.templates.h index 37aa2128da..6df7772742 100644 --- a/deal.II/lac/include/lac/constraint_matrix.templates.h +++ b/deal.II/lac/include/lac/constraint_matrix.templates.h @@ -1010,62 +1010,88 @@ namespace internals // is much more expensive struct DataCache { - DataCache () : element_size (0), data (0) {}; - ~DataCache() { if (data != 0) {delete [] data;} }; - void reinit () { Assert (element_size == 0, ExcInternalError()); - element_size = 6; data = new std::pair [20*6]; - individual_size.resize(20), n_used_elements = 0;}; - unsigned int element_size; - std::pair * data; - std::vector individual_size; - unsigned int n_used_elements; - - unsigned int insert_new_index (const std::pair &pair) - { - if (element_size == 0) - reinit(); - if (n_used_elements == individual_size.size()) + DataCache () + : + element_size (0), + data (0), + n_used_elements(0) + {} + + ~DataCache() { - std::pair * new_data = - new std::pair [2*individual_size.size()*element_size]; - memcpy (new_data, data, individual_size.size()*element_size* - sizeof(std::pair)); - delete [] data; - data = new_data; - individual_size.resize (2*individual_size.size(), 0); + if (data != 0) + delete [] data; } - unsigned int index = n_used_elements; - data[index*element_size] = pair; - individual_size[index] = 1; - ++n_used_elements; - return index; - } - void append_index (const unsigned int index, - const std::pair &pair) - { - Assert (index < n_used_elements, ExcIndexRange (index, 0, n_used_elements)); - const unsigned int my_size = individual_size[index]; - if (my_size == element_size) + void reinit () { - std::pair * new_data = - new std::pair [2*individual_size.size()*element_size]; - for (unsigned int i=0; i)); - delete [] data; - data = new_data; - element_size *= 2; + Assert (element_size == 0, ExcInternalError()); + element_size = 6; + data = new std::pair [20*6]; + individual_size.resize(20); + n_used_elements = 0; } - data[index*element_size+my_size] = pair; - individual_size[index]++; - }; - unsigned int - get_size (const unsigned int index) const { return individual_size[index]; }; + unsigned int element_size; + + std::pair * data; + + std::vector individual_size; + + unsigned int n_used_elements; + + unsigned int insert_new_index (const std::pair &pair) + { + if (element_size == 0) + reinit(); + if (n_used_elements == individual_size.size()) + { + std::pair * new_data = + new std::pair [2*individual_size.size()*element_size]; + memcpy (new_data, data, individual_size.size()*element_size* + sizeof(std::pair)); + delete [] data; + data = new_data; + individual_size.resize (2*individual_size.size(), 0); + } + unsigned int index = n_used_elements; + data[index*element_size] = pair; + individual_size[index] = 1; + ++n_used_elements; + return index; + } - const std::pair * - get_entry (const unsigned int index) const { return &data[index*element_size]; }; + void append_index (const unsigned int index, + const std::pair &pair) + { + Assert (index < n_used_elements, ExcIndexRange (index, 0, n_used_elements)); + const unsigned int my_size = individual_size[index]; + if (my_size == element_size) + { + std::pair * new_data = + new std::pair [2*individual_size.size()*element_size]; + for (unsigned int i=0; i)); + delete [] data; + data = new_data; + element_size *= 2; + } + data[index*element_size+my_size] = pair; + individual_size[index]++; + } + + unsigned int + get_size (const unsigned int index) const + { + return individual_size[index]; + } + + const std::pair * + get_entry (const unsigned int index) const + { + return &data[index*element_size]; + } };