feat: reduce mutex waits in parallel finder

This commit is contained in:
mandlm 2024-03-20 13:33:47 +01:00
parent ba460cc00a
commit 1ab711f81c
Signed by: mandlm
GPG Key ID: 4AA25D647AA54CC7

View File

@ -27,13 +27,17 @@ ParallelFinder::find_prefix(string_view search_term) const {
[](const vector<string> &word_list, const string_view &search_term,
forward_list<const string *> &result, size_t start_index,
size_t end_index, mutex &result_mutex) {
forward_list<const string *> thread_results;
for (size_t index = start_index; index < end_index; ++index) {
const auto &current_word = word_list[index];
if (current_word.starts_with(search_term)) {
const lock_guard<mutex> lock(result_mutex);
result.push_front(&current_word);
thread_results.push_front(&current_word);
}
}
if (!thread_results.empty()) {
const lock_guard<mutex> lock(result_mutex);
result.merge(thread_results);
}
},
cref(word_list_), cref(search_term), ref(result), first_word_index,
last_word_index, ref(result_mutex));