From 3da06af983c8ccb624dacc64a7da8ab45f8d89ae Mon Sep 17 00:00:00 2001 From: David Wells Date: Sun, 30 Dec 2018 10:38:32 -0500 Subject: [PATCH] Remove some unnecessary downcasts to int. 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 | 24 ++++++++++-------------- source/lac/trilinos_sparsity_pattern.cc | 16 ++++++---------- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/source/lac/trilinos_sparse_matrix.cc b/source/lac/trilinos_sparse_matrix.cc index b181dcac42..edce04ddb7 100644 --- a/source/lac/trilinos_sparse_matrix.cc +++ b/source/lac/trilinos_sparse_matrix.cc @@ -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(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(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(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 diff --git a/source/lac/trilinos_sparsity_pattern.cc b/source/lac/trilinos_sparsity_pattern.cc index c6769aa313..454c0ca394 100644 --- a/source/lac/trilinos_sparsity_pattern.cc +++ b/source/lac/trilinos_sparsity_pattern.cc @@ -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(trilinos_j)); - - const int local_col_index = static_cast(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; -- 2.39.5