Skip to content

Commit

Permalink
citnames: use parallel stl
Browse files Browse the repository at this point in the history
  • Loading branch information
rizsotto authored and lnagyatatlassian committed Dec 27, 2022
1 parent 66fd11d commit 728300c
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions source/citnames/source/Application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include "collect/db/EventsDatabaseReader.h"
#include "libsys/Path.h"

#include <algorithm>
#include <execution>
#include <filesystem>

#ifdef HAVE_FMT_STD_H
Expand Down Expand Up @@ -169,15 +171,21 @@ namespace {
}

size_t transform(cs::semantic::Build &build, const db::EventsDatabaseReader::Ptr& events, std::list<cs::Entry> &output) {
for (const auto &event : *events) {
const auto entries = build.recognize(event)
.map<std::list<cs::Entry>>([](const auto &semantic) -> std::list<cs::Entry> {
const auto candidate = dynamic_cast<const cs::semantic::CompilerCall *>(semantic.get());
return (candidate != nullptr) ? candidate->into_entries() : std::list<cs::Entry>();
})
.unwrap_or({});
std::copy(entries.begin(), entries.end(), std::back_inserter(output));
}
std::mutex mutex;
std::for_each(std::execution::par,
events->begin(), events->end(),
[&output, &mutex, &build](const auto &event) {
const auto entries = build.recognize(event)
.template map<std::list<cs::Entry>>([](const auto &semantic) -> std::list<cs::Entry> {
const auto candidate = dynamic_cast<const cs::semantic::CompilerCall *>(semantic.get());
return (candidate != nullptr) ? candidate->into_entries() : std::list<cs::Entry>();
})
.unwrap_or({});
{
const std::lock_guard<std::mutex> lock(mutex);
std::copy(entries.begin(), entries.end(), std::back_inserter(output));
}
});
return output.size();
}
}
Expand Down

0 comments on commit 728300c

Please sign in to comment.