mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 10:17:35 +00:00
Assistant: Avoid copying the result vectors when providers finish
Just move() them instead to cut down on the copying. :^)
This commit is contained in:
parent
e4199beccc
commit
94def5ae9d
1 changed files with 49 additions and 40 deletions
|
@ -81,7 +81,7 @@ void AppProvider::query(String const& query, Function<void(NonnullRefPtrVector<R
|
|||
results.append(adopt_ref(*new AppResult(icon.bitmap_for_size(16), app_file->name(), {}, app_file, match_result.score)));
|
||||
});
|
||||
|
||||
on_complete(results);
|
||||
on_complete(move(results));
|
||||
}
|
||||
|
||||
void CalculatorProvider::query(String const& query, Function<void(NonnullRefPtrVector<Result>)> on_complete)
|
||||
|
@ -112,7 +112,7 @@ void CalculatorProvider::query(String const& query, Function<void(NonnullRefPtrV
|
|||
|
||||
NonnullRefPtrVector<Result> results;
|
||||
results.append(adopt_ref(*new CalculatorResult(calculation)));
|
||||
on_complete(results);
|
||||
on_complete(move(results));
|
||||
}
|
||||
|
||||
Gfx::Bitmap const* FileResult::bitmap() const
|
||||
|
@ -132,7 +132,8 @@ void FileProvider::query(const String& query, Function<void(NonnullRefPtrVector<
|
|||
if (m_fuzzy_match_work)
|
||||
m_fuzzy_match_work->cancel();
|
||||
|
||||
m_fuzzy_match_work = Threading::BackgroundAction<NonnullRefPtrVector<Result>>::create([this, query](auto& task) {
|
||||
m_fuzzy_match_work = Threading::BackgroundAction<NonnullRefPtrVector<Result>>::create(
|
||||
[this, query](auto& task) {
|
||||
NonnullRefPtrVector<Result> results;
|
||||
|
||||
for (auto& path : m_full_path_cache) {
|
||||
|
@ -147,7 +148,11 @@ void FileProvider::query(const String& query, Function<void(NonnullRefPtrVector<
|
|||
|
||||
results.append(adopt_ref(*new FileResult(path, match_result.score)));
|
||||
}
|
||||
return results; }, [on_complete = move(on_complete)](auto results) { on_complete(results); });
|
||||
return results;
|
||||
},
|
||||
[on_complete = move(on_complete)](auto results) {
|
||||
on_complete(move(results));
|
||||
});
|
||||
}
|
||||
|
||||
void FileProvider::build_filesystem_cache()
|
||||
|
@ -158,7 +163,8 @@ void FileProvider::build_filesystem_cache()
|
|||
m_building_cache = true;
|
||||
m_work_queue.enqueue("/");
|
||||
|
||||
Threading::BackgroundAction<int>::create([this](auto&) {
|
||||
Threading::BackgroundAction<int>::create(
|
||||
[this](auto&) {
|
||||
String slash = "/";
|
||||
Core::ElapsedTimer timer;
|
||||
timer.start();
|
||||
|
@ -187,8 +193,11 @@ void FileProvider::build_filesystem_cache()
|
|||
}
|
||||
}
|
||||
dbgln("Built cache in {} ms", timer.elapsed());
|
||||
|
||||
return 0; }, [this](auto) { m_building_cache = false; });
|
||||
return 0;
|
||||
},
|
||||
[this](auto) {
|
||||
m_building_cache = false;
|
||||
});
|
||||
}
|
||||
|
||||
void TerminalProvider::query(String const& query, Function<void(NonnullRefPtrVector<Result>)> on_complete)
|
||||
|
@ -200,7 +209,7 @@ void TerminalProvider::query(String const& query, Function<void(NonnullRefPtrVec
|
|||
|
||||
NonnullRefPtrVector<Result> results;
|
||||
results.append(adopt_ref(*new TerminalResult(move(command))));
|
||||
on_complete(results);
|
||||
on_complete(move(results));
|
||||
}
|
||||
|
||||
void URLProvider::query(String const& query, Function<void(NonnullRefPtrVector<Result>)> on_complete)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue