]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Remove some unnecessary downcasts to int.
authorDavid Wells <drwells@email.unc.edu>
Sun, 30 Dec 2018 15:38:32 +0000 (10:38 -0500)
committerDavid Wells <drwells@email.unc.edu>
Sun, 30 Dec 2018 16:23:26 +0000 (11:23 -0500)
This value is always used as an array index so we can keep it as std::ptrdiff_t
instead of downcasting to int.

Note that the line

    if (diag_find && std::fabs(...) == 0.0 ...)

checked the wrong thing: diag_find would have, if we did not find the value, be
set to col_indices + num_entries, not NULL.

source/lac/trilinos_sparse_matrix.cc
source/lac/trilinos_sparsity_pattern.cc

index b181dcac422de3c3e36cd533eaa7ef6180557dfb..edce04ddb7a439d272f57465f597c28f27baa990 100644 (file)
@@ -1246,15 +1246,15 @@ namespace TrilinosWrappers
 
         Assert(ierr == 0, ExcTrilinosError(ierr));
 
-        int *diag_find =
-          std::find(col_indices, col_indices + num_entries, local_row);
-        int diag_index = static_cast<int>(diag_find - col_indices);
+        const std::ptrdiff_t diag_index =
+          std::find(col_indices, col_indices + num_entries, local_row) -
+          col_indices;
 
         for (TrilinosWrappers::types::int_type j = 0; j < num_entries; ++j)
           if (diag_index != j || new_diag_value == 0)
             values[j] = 0.;
 
-        if (diag_find && std::fabs(values[diag_index]) == 0.0 &&
+        if (diag_index != num_entries && std::fabs(values[diag_index]) == 0.0 &&
             new_diag_value != 0.0)
           values[diag_index] = new_diag_value;
       }
@@ -1326,11 +1326,9 @@ namespace TrilinosWrappers
         // Search the index where we
         // look for the value, and then
         // finally get it.
-
-        int *el_find =
-          std::find(col_indices, col_indices + nnz_present, trilinos_j);
-
-        int local_col_index = static_cast<int>(el_find - col_indices);
+        const std::ptrdiff_t local_col_index =
+          std::find(col_indices, col_indices + nnz_present, trilinos_j) -
+          col_indices;
 
         // This is actually the only
         // difference to the el(i,j)
@@ -1403,11 +1401,9 @@ namespace TrilinosWrappers
         // Search the index where we
         // look for the value, and then
         // finally get it.
-        int *el_find =
-          std::find(col_indices, col_indices + nnz_present, trilinos_j);
-
-        int local_col_index = static_cast<int>(el_find - col_indices);
-
+        const std::ptrdiff_t local_col_index =
+          std::find(col_indices, col_indices + nnz_present, trilinos_j) -
+          col_indices;
 
         // This is actually the only
         // difference to the () function
index c6769aa3138e6fdb659eff5456bcaf9f3243eabb..454c0ca394f25832ace1a74d1f6440537fde73d1 100644 (file)
@@ -874,11 +874,9 @@ namespace TrilinosWrappers
                    ExcDimensionMismatch(nnz_present, nnz_extracted));
 
             // Search the index
-            TrilinosWrappers::types::int_type *el_find =
-              std::find(col_indices, col_indices + nnz_present, trilinos_j);
-
-            const TrilinosWrappers::types::int_type local_col_index =
-              el_find - col_indices;
+            const std::ptrdiff_t local_col_index =
+              std::find(col_indices, col_indices + nnz_present, trilinos_j) -
+              col_indices;
 
             if (local_col_index == nnz_present)
               return false;
@@ -903,11 +901,9 @@ namespace TrilinosWrappers
                    ExcDimensionMismatch(nnz_present, nnz_extracted));
 
             // Search the index
-            int *el_find = std::find(col_indices,
-                                     col_indices + nnz_present,
-                                     static_cast<int>(trilinos_j));
-
-            const int local_col_index = static_cast<int>(el_find - col_indices);
+            const std::ptrdiff_t local_col_index =
+              std::find(col_indices, col_indices + nnz_present, trilinos_j) -
+              col_indices;
 
             if (local_col_index == nnz_present)
               return 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.