]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Use range-based for loops in a number of places.
authorWolfgang Bangerth <bangerth@colostate.edu>
Wed, 8 Dec 2021 16:50:01 +0000 (09:50 -0700)
committerMatthias Maier <tamiko@43-1.org>
Wed, 12 Jan 2022 10:18:55 +0000 (04:18 -0600)
include/deal.II/base/work_stream.h

index 4ab83ce9f020bb8f827677b8ea9dcaca3281d434..86e18a09c87a16487ab9025e4a51476cbcd12dd7 100644 (file)
@@ -332,18 +332,16 @@ namespace WorkStream
           , chunk_size(chunk_size)
         {
           // initialize the elements of the ring buffer
-          for (unsigned int element = 0; element < item_buffer.size();
-               ++element)
+          for (auto &item : item_buffer)
             {
-              Assert(item_buffer[element].n_items == 0, ExcInternalError());
-
-              item_buffer[element].work_items.resize(
-                chunk_size, remaining_iterator_range.second);
-              item_buffer[element].scratch_data        = &thread_local_scratch;
-              item_buffer[element].sample_scratch_data = &sample_scratch_data;
-              item_buffer[element].copy_datas.resize(chunk_size,
-                                                     sample_copy_data);
-              item_buffer[element].currently_in_use = false;
+              Assert(item.n_items == 0, ExcInternalError());
+
+              item.work_items.resize(chunk_size,
+                                     remaining_iterator_range.second);
+              item.scratch_data        = &thread_local_scratch;
+              item.sample_scratch_data = &sample_scratch_data;
+              item.copy_datas.resize(chunk_size, sample_copy_data);
+              item.currently_in_use = false;
             }
         }
 
@@ -524,19 +522,14 @@ namespace WorkStream
             // not have to lock the following section
             ScratchData *scratch_data = nullptr;
             {
-              typename ItemType::ScratchDataList &scratch_data_list =
-                current_item->scratch_data->get();
-
               // see if there is an unused object. if so, grab it and mark
               // it as used
-              for (typename ItemType::ScratchDataList::iterator p =
-                     scratch_data_list.begin();
-                   p != scratch_data_list.end();
-                   ++p)
+              for (auto &p : current_item->scratch_data->get())
                 if (p->currently_in_use == false)
                   {
-                    scratch_data        = p->scratch_data.get();
-                    p->currently_in_use = true;
+                    scratch_data       = p.scratch_data.get();
+                    p.currently_in_use = true;
+
                     break;
                   }
 
@@ -545,10 +538,7 @@ namespace WorkStream
                 {
                   scratch_data =
                     new ScratchData(*current_item->sample_scratch_data);
-
-                  typename ItemType::ScratchDataList::value_type
-                    new_scratch_object(scratch_data, true);
-                  scratch_data_list.push_back(std::move(new_scratch_object));
+                  current_item->scratch_data->get().emplace_back(scratch_data, true);
                 }
             }
 
@@ -578,22 +568,14 @@ namespace WorkStream
             // finally mark the scratch object as unused again. as above, there
             // is no need to lock anything here since the object we work on
             // is thread-local
-            {
-              typename ItemType::ScratchDataList &scratch_data_list =
-                current_item->scratch_data->get();
-
-              for (typename ItemType::ScratchDataList::iterator p =
-                     scratch_data_list.begin();
-                   p != scratch_data_list.end();
-                   ++p)
-                if (p->scratch_data.get() == scratch_data)
-                  {
-                    Assert(p->currently_in_use == true, ExcInternalError());
-                    p->currently_in_use = false;
+            for (auto &p : current_item->scratch_data->get())
+              if (p.scratch_data.get() == scratch_data)
+                {
+                  Assert(p.currently_in_use == true, ExcInternalError());
+                  p.currently_in_use = false;
 
-                    break;
-                  }
-            }
+                  break;
+                }
 
             // if there is no copier, mark current item as usable again
             if (copier_exist == false)

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.