feat: reduce mutex waits in parallel finder
This commit is contained in:
parent
ba460cc00a
commit
1ab711f81c
@ -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 ¤t_word = word_list[index];
|
||||
if (current_word.starts_with(search_term)) {
|
||||
const lock_guard<mutex> lock(result_mutex);
|
||||
result.push_front(¤t_word);
|
||||
thread_results.push_front(¤t_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));
|
||||
|
Reference in New Issue
Block a user