mirror of
https://github.com/hoytech/strfry.git
synced 2025-06-15 16:13:00 +00:00
use const refs for std::function callbacks
This commit is contained in:
@ -85,7 +85,7 @@ struct ActiveMonitors : NonCopyable {
|
||||
conns.erase(connId);
|
||||
}
|
||||
|
||||
void process(lmdb::txn &txn, defaultDb::environment::View_Event &ev, std::function<void(RecipientList &&, uint64_t)> cb) {
|
||||
void process(lmdb::txn &txn, defaultDb::environment::View_Event &ev, const std::function<void(RecipientList &&, uint64_t)> &cb) {
|
||||
RecipientList recipients;
|
||||
|
||||
auto processMonitorSet = [&](MonitorSet &ms){
|
||||
@ -101,7 +101,7 @@ struct ActiveMonitors : NonCopyable {
|
||||
}
|
||||
};
|
||||
|
||||
auto processMonitorsExact = [&]<typename T>(btree_map<T, MonitorSet> &m, const T &key, std::function<bool(const T &)> matches){
|
||||
auto processMonitorsExact = [&]<typename T>(btree_map<T, MonitorSet> &m, const T &key, const std::function<bool(const T &)> &matches){
|
||||
auto it = m.upper_bound(key);
|
||||
|
||||
if (it == m.begin()) return;
|
||||
@ -118,21 +118,21 @@ struct ActiveMonitors : NonCopyable {
|
||||
|
||||
{
|
||||
Bytes32 id(packed.id());
|
||||
processMonitorsExact(allIds, id, static_cast<std::function<bool(const Bytes32&)>>([&](const Bytes32 &val){
|
||||
processMonitorsExact(allIds, id, static_cast<const std::function<bool(const Bytes32&)> &>([&](const Bytes32 &val){
|
||||
return id == val;
|
||||
}));
|
||||
}
|
||||
|
||||
{
|
||||
Bytes32 pubkey(packed.pubkey());
|
||||
processMonitorsExact(allAuthors, pubkey, static_cast<std::function<bool(const Bytes32&)>>([&](const Bytes32 &val){
|
||||
processMonitorsExact(allAuthors, pubkey, static_cast<const std::function<bool(const Bytes32&)> &>([&](const Bytes32 &val){
|
||||
return pubkey == val;
|
||||
}));
|
||||
}
|
||||
|
||||
packed.foreachTag([&](char tagName, std::string_view tagVal){
|
||||
auto &tagSpec = getTagSpec(tagName, tagVal);
|
||||
processMonitorsExact(allTags, tagSpec, static_cast<std::function<bool(const std::string&)>>([&](const std::string &val){
|
||||
processMonitorsExact(allTags, tagSpec, static_cast<const std::function<bool(const std::string&)> &>([&](const std::string &val){
|
||||
return tagSpec == val;
|
||||
}));
|
||||
return true;
|
||||
@ -140,7 +140,7 @@ struct ActiveMonitors : NonCopyable {
|
||||
|
||||
{
|
||||
auto kind = packed.kind();
|
||||
processMonitorsExact(allKinds, kind, static_cast<std::function<bool(const uint64_t&)>>([&](const uint64_t &val){
|
||||
processMonitorsExact(allKinds, kind, static_cast<const std::function<bool(const uint64_t&)> &>([&](const uint64_t &val){
|
||||
return kind == val;
|
||||
}));
|
||||
}
|
||||
|
@ -226,7 +226,7 @@ struct DBScan : NonCopyable {
|
||||
refillScanDepth = 10 * initialScanDepth;
|
||||
}
|
||||
|
||||
bool scan(lmdb::txn &txn, std::function<bool(uint64_t)> handleEvent, std::function<bool(uint64_t)> doPause) {
|
||||
bool scan(lmdb::txn &txn, const std::function<bool(uint64_t)> &handleEvent, const std::function<bool(uint64_t)> &doPause) {
|
||||
auto cmp = [](auto &a, auto &b){
|
||||
return a.created() == b.created() ? a.levId() > b.levId() : a.created() > b.created();
|
||||
};
|
||||
@ -299,7 +299,7 @@ struct DBQuery : NonCopyable {
|
||||
DBQuery(const tao::json::value &filter, uint64_t maxLimit = MAX_U64) : sub(Subscription(1, ".", NostrFilterGroup::unwrapped(filter, maxLimit))) {}
|
||||
|
||||
// If scan is complete, returns true
|
||||
bool process(lmdb::txn &txn, std::function<void(const Subscription &, uint64_t)> cb, uint64_t timeBudgetMicroseconds = MAX_U64, bool logMetrics = false) {
|
||||
bool process(lmdb::txn &txn, const std::function<void(const Subscription &, uint64_t)> &cb, uint64_t timeBudgetMicroseconds = MAX_U64, bool logMetrics = false) {
|
||||
while (filterGroupIndex < sub.filterGroup.size()) {
|
||||
const auto &f = sub.filterGroup.filters[filterGroupIndex];
|
||||
|
||||
@ -370,7 +370,7 @@ struct DBQuery : NonCopyable {
|
||||
};
|
||||
|
||||
|
||||
inline void foreachByFilter(lmdb::txn &txn, const tao::json::value &filter, std::function<void(uint64_t)> cb) {
|
||||
inline void foreachByFilter(lmdb::txn &txn, const tao::json::value &filter, const std::function<void(uint64_t)> &cb) {
|
||||
DBQuery query(filter);
|
||||
|
||||
query.process(txn, [&](const auto &, uint64_t levId){
|
||||
|
@ -19,7 +19,7 @@ struct ThreadPool {
|
||||
join();
|
||||
}
|
||||
|
||||
void init(std::string name, uint64_t numThreads_, std::function<void(Thread &t)> cb) {
|
||||
void init(std::string name, uint64_t numThreads_, const std::function<void(Thread &t)> &cb) {
|
||||
if (numThreads_ == 0) throw herr("must have more than 0 threads");
|
||||
|
||||
numThreads = numThreads_;
|
||||
@ -49,7 +49,7 @@ struct ThreadPool {
|
||||
pool[who].inbox.push_move_all(m);
|
||||
}
|
||||
|
||||
void dispatchToAll(std::function<M()> cb) {
|
||||
void dispatchToAll(const std::function<M()> &cb) {
|
||||
for (size_t i = 0; i < numThreads; i++) pool[i].inbox.push_move(cb());
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user