From e7eccf3de2bf77ad72109e99a8a490aee0fc1250 Mon Sep 17 00:00:00 2001 From: Karol Kosek Date: Thu, 14 Oct 2021 18:36:08 +0200 Subject: [PATCH] Assistant: Simplify the logic of calculating bonus points This does not change the results, but makes the code clearer. --- .../Applications/Assistant/FuzzyMatch.cpp | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Userland/Applications/Assistant/FuzzyMatch.cpp b/Userland/Applications/Assistant/FuzzyMatch.cpp index e169847ba2..3453fb0634 100644 --- a/Userland/Applications/Assistant/FuzzyMatch.cpp +++ b/Userland/Applications/Assistant/FuzzyMatch.cpp @@ -37,24 +37,24 @@ static int calculate_score(String const& string, u8* index_points, size_t index_ for (size_t i = 0; i < index_points_size; i++) { u8 current_idx = index_points[i]; - if (i > 0) { - u8 previous_idx = index_points[i - 1]; - if (current_idx == previous_idx) - out_score += SEQUENTIAL_BONUS; - } - - if (current_idx > 0) { - u32 current_character = string[current_idx]; - u32 neighbor_character = string[current_idx - 1]; - - if (neighbor_character != to_ascii_uppercase(neighbor_character) && current_character != to_ascii_lowercase(current_character)) - out_score += CAMEL_BONUS; - - if (neighbor_character == '_' || neighbor_character == ' ') - out_score += SEPARATOR_BONUS; - } else { + if (current_idx == 0) out_score += FIRST_LETTER_BONUS; - } + + if (i == 0) + continue; + + u8 previous_idx = index_points[i - 1]; + if (current_idx == previous_idx) + out_score += SEQUENTIAL_BONUS; + + u32 current_character = string[current_idx]; + u32 neighbor_character = string[current_idx - 1]; + + if (neighbor_character != to_ascii_uppercase(neighbor_character) && current_character != to_ascii_lowercase(current_character)) + out_score += CAMEL_BONUS; + + if (neighbor_character == '_' || neighbor_character == ' ') + out_score += SEPARATOR_BONUS; } return out_score;