From c450576c72c1146518b03942b11541b74bf10fc3 Mon Sep 17 00:00:00 2001 From: Denes Tarjan Date: Thu, 4 Apr 2024 18:53:05 +0200 Subject: [PATCH] [NFC] Eliminate unneeded code branches in workspace.h --- .../intrinsiccv/morphology/workspace.h | 117 +++++++++--------- 1 file changed, 57 insertions(+), 60 deletions(-) diff --git a/intrinsiccv/include/intrinsiccv/morphology/workspace.h b/intrinsiccv/include/intrinsiccv/morphology/workspace.h index 8488a0203..9980bebfe 100644 --- a/intrinsiccv/include/intrinsiccv/morphology/workspace.h +++ b/intrinsiccv/include/intrinsiccv/morphology/workspace.h @@ -199,66 +199,63 @@ class MorphologyWorkspace final { auto first_src_rows = src_rows; auto last_src_rows = src_rows.at(rect.height() - 1); - if (size_t horizontal_height = get_next_horizontal_height()) { - for (size_t index = 0; index < horizontal_height; ++index) { - switch (border_type) { - case BorderType::CONSTANT: { - make_constant_border(wide_rows, 0, margin.left(), - left_border_value); - - if (row_index_ < margin.top()) { - make_constant_border(wide_rows, margin.left(), - wide_rows_src_width_, top_border_value); - } else if (row_index_ < (margin.top() + rect.height())) { - copy_data(src_rows, wide_rows.at(0, margin.left()), - wide_rows_src_width_); - // Advance source rows. - ++src_rows; - } else if (row_index_ >= (margin.top() + rect.height())) { - make_constant_border(wide_rows, margin.left(), - wide_rows_src_width_, bottom_border_value); - } - - make_constant_border(wide_rows, - margin.left() + wide_rows_src_width_, - margin.right(), right_border_value); - - // Advance counters. - ++row_index_; - } break; - - case BorderType::REPLICATE: { - Rows current_src_row; - - if (row_index_ < margin.top()) { - current_src_row = first_src_rows; - } else if (row_index_ < (margin.top() + rect.height())) { - current_src_row = src_rows; - // Advance source rows. - ++src_rows; - } else { - current_src_row = last_src_rows; - } - - replicate_border(current_src_row, wide_rows, 0, 0, margin.left()); - copy_data(current_src_row, wide_rows.at(0, margin.left()), + size_t horizontal_height = get_next_horizontal_height(); + for (size_t index = 0; index < horizontal_height; ++index) { + switch (border_type) { + case BorderType::CONSTANT: { + make_constant_border(wide_rows, 0, margin.left(), left_border_value); + + if (row_index_ < margin.top()) { + make_constant_border(wide_rows, margin.left(), wide_rows_src_width_, + top_border_value); + } else if (row_index_ < (margin.top() + rect.height())) { + copy_data(src_rows, wide_rows.at(0, margin.left()), wide_rows_src_width_); - replicate_border( - current_src_row, wide_rows, wide_rows_src_width_ - 1, - margin.left() + wide_rows_src_width_, margin.right()); - - // Advance counters. - ++row_index_; - } break; - } // switch (border_type) - - // [Step 2] Process the preloaded data. - operation.process_horizontal(Rectangle{rect.width(), 1UL}, wide_rows, - db_indirect_rows.write_at().at(index)); - } // for (...; index < horizontal_height; ...) - - db_indirect_rows.swap(); - } + // Advance source rows. + ++src_rows; + } else { + make_constant_border(wide_rows, margin.left(), wide_rows_src_width_, + bottom_border_value); + } + + make_constant_border(wide_rows, margin.left() + wide_rows_src_width_, + margin.right(), right_border_value); + + // Advance counters. + ++row_index_; + } break; + + case BorderType::REPLICATE: { + Rows current_src_row; + + if (row_index_ < margin.top()) { + current_src_row = first_src_rows; + } else if (row_index_ < (margin.top() + rect.height())) { + current_src_row = src_rows; + // Advance source rows. + ++src_rows; + } else { + current_src_row = last_src_rows; + } + + replicate_border(current_src_row, wide_rows, 0, 0, margin.left()); + copy_data(current_src_row, wide_rows.at(0, margin.left()), + wide_rows_src_width_); + replicate_border(current_src_row, wide_rows, wide_rows_src_width_ - 1, + margin.left() + wide_rows_src_width_, + margin.right()); + + // Advance counters. + ++row_index_; + } break; + } // switch (border_type) + + // [Step 2] Process the preloaded data. + operation.process_horizontal(Rectangle{rect.width(), 1UL}, wide_rows, + db_indirect_rows.write_at().at(index)); + } // for (...; index < horizontal_height; ...) + + db_indirect_rows.swap(); // [Step 3] Process any remaining data. while (vertical_height_) { @@ -272,7 +269,7 @@ class MorphologyWorkspace final { wide_rows_src_width_); // Advance source rows. ++src_rows; - } else if (row_index_ >= (margin.top() + rect.height())) { + } else { make_constant_border(wide_rows, margin.left(), wide_rows_src_width_, bottom_border_value); } -- GitLab