summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarol Kosek <krkk@serenityos.org>2021-10-14 18:36:08 +0200
committerAndreas Kling <kling@serenityos.org>2021-10-25 13:00:32 +0200
commite7eccf3de2bf77ad72109e99a8a490aee0fc1250 (patch)
tree760287c57d7c4a748af7614cbcadf6f8a50c82ad
parentee17614e34538cacc726769766fea4f072c4b075 (diff)
downloadserenity-e7eccf3de2bf77ad72109e99a8a490aee0fc1250.zip
Assistant: Simplify the logic of calculating bonus points
This does not change the results, but makes the code clearer.
-rw-r--r--Userland/Applications/Assistant/FuzzyMatch.cpp30
1 files changed, 15 insertions, 15 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)
+ out_score += FIRST_LETTER_BONUS;
- if (current_idx > 0) {
- u32 current_character = string[current_idx];
- u32 neighbor_character = string[current_idx - 1];
+ if (i == 0)
+ continue;
- if (neighbor_character != to_ascii_uppercase(neighbor_character) && current_character != to_ascii_lowercase(current_character))
- out_score += CAMEL_BONUS;
+ u8 previous_idx = index_points[i - 1];
+ if (current_idx == previous_idx)
+ out_score += SEQUENTIAL_BONUS;
- if (neighbor_character == '_' || neighbor_character == ' ')
- out_score += SEPARATOR_BONUS;
- } else {
- out_score += FIRST_LETTER_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;