diff --git a/include/opendht/dht.h b/include/opendht/dht.h index 7f750795f570b1025382447ab2bf0e7cde64a1bd..46da9994d52a899c7996250566e561e6c7bbc251 100644 --- a/include/opendht/dht.h +++ b/include/opendht/dht.h @@ -163,7 +163,7 @@ public: /** * Get locally stored data for the given hash. */ - std::vector<Sp<Value>> getLocal(const InfoHash& key, Value::Filter f = Value::AllFilter()) const; + std::vector<Sp<Value>> getLocal(const InfoHash& key, Value::Filter f = {}) const; /** * Get locally stored data for the given key and value id. @@ -469,7 +469,7 @@ private: Sp<Search> search(const InfoHash& id, sa_family_t af, GetCallback = {}, QueryCallback = {}, DoneCallback = {}, Value::Filter = {}, const Sp<Query>& q = {}); void announce(const InfoHash& id, sa_family_t af, Sp<Value> value, DoneCallback callback, time_point created=time_point::max(), bool permanent = false); - size_t listenTo(const InfoHash& id, sa_family_t af, ValueCallback cb, Value::Filter f = Value::AllFilter(), const Sp<Query>& q = {}); + size_t listenTo(const InfoHash& id, sa_family_t af, ValueCallback cb, Value::Filter f = {}, const Sp<Query>& q = {}); /** * Refill the search with good nodes if possible. diff --git a/include/opendht/dht_interface.h b/include/opendht/dht_interface.h index bf837492c19289564c17c238776fa7043ebae8b9..82b7bf85cc565cc358eaeec9f7703b12f883f843 100644 --- a/include/opendht/dht_interface.h +++ b/include/opendht/dht_interface.h @@ -106,7 +106,7 @@ public: /** * Get locally stored data for the given hash. */ - virtual std::vector<Sp<Value>> getLocal(const InfoHash& key, Value::Filter f = Value::AllFilter()) const = 0; + virtual std::vector<Sp<Value>> getLocal(const InfoHash& key, Value::Filter f = {}) const = 0; /** * Get locally stored data for the given key and value id. diff --git a/include/opendht/dhtrunner.h b/include/opendht/dhtrunner.h index 60a2110fe4a059a23b4f47ab9a95b5ba4bd82e04..e74391313d69d2cde7cddaf161e3558439bd2f49 100644 --- a/include/opendht/dhtrunner.h +++ b/include/opendht/dhtrunner.h @@ -63,20 +63,20 @@ public: DhtRunner(); virtual ~DhtRunner(); - void get(InfoHash id, GetCallbackSimple cb, DoneCallback donecb={}, Value::Filter f = Value::AllFilter(), Where w = {}) { + void get(InfoHash id, GetCallbackSimple cb, DoneCallback donecb={}, Value::Filter f = {}, Where w = {}) { get(id, bindGetCb(cb), donecb, f, w); } - void get(InfoHash id, GetCallbackSimple cb, DoneCallbackSimple donecb={}, Value::Filter f = Value::AllFilter(), Where w = {}) { + void get(InfoHash id, GetCallbackSimple cb, DoneCallbackSimple donecb={}, Value::Filter f = {}, Where w = {}) { get(id, bindGetCb(cb), donecb, f, w); } void get(InfoHash hash, GetCallback vcb, DoneCallback dcb, Value::Filter f={}, Where w = {}); - void get(InfoHash id, GetCallback cb, DoneCallbackSimple donecb={}, Value::Filter f = Value::AllFilter(), Where w = {}) { + void get(InfoHash id, GetCallback cb, DoneCallbackSimple donecb={}, Value::Filter f = {}, Where w = {}) { get(id, cb, bindDoneCb(donecb), f, w); } - void get(const std::string& key, GetCallback vcb, DoneCallbackSimple dcb={}, Value::Filter f = Value::AllFilter(), Where w = {}); + void get(const std::string& key, GetCallback vcb, DoneCallbackSimple dcb={}, Value::Filter f = {}, Where w = {}); template <class T> void get(InfoHash hash, std::function<bool(std::vector<T>&&)> cb, DoneCallbackSimple dcb={}) diff --git a/include/opendht/value.h b/include/opendht/value.h index a4a3348a1c0b019bcccecb465e5295f5c2c55280..34224ff7cd58db9f5e5525f7af8205863236b8aa 100644 --- a/include/opendht/value.h +++ b/include/opendht/value.h @@ -165,8 +165,8 @@ struct OPENDHT_PUBLIC Value return chainOr(std::move(f1), std::move(f2)); } static Filter chain(Filter&& f1, Filter&& f2) { - if (not f1) return f2; - if (not f2) return f1; + if (not f1) return std::move(f1); + if (not f2) return std::move(f2); return [f1,f2](const Value& v) { return f1(v) and f2(v); }; @@ -184,7 +184,7 @@ struct OPENDHT_PUBLIC Value return chainAll(std::vector<Filter>(l.begin(), l.end())); } static Filter chainOr(Filter&& f1, Filter&& f2) { - if (not f1 or not f2) return AllFilter(); + if (not f1 or not f2) return {}; return [f1,f2](const Value& v) { return f1(v) or f2(v); }; @@ -990,7 +990,7 @@ template <typename T, Value::Filter getFilterSet() { - return Value::AllFilter(); + return {}; } template <class T> diff --git a/src/securedht.cpp b/src/securedht.cpp index 636ac6bc84ee015dc8e7fc5d40ed81132e272e97..4be57f74ebb03c61a38be480db1821f90c6d31ed 100644 --- a/src/securedht.cpp +++ b/src/securedht.cpp @@ -284,6 +284,8 @@ SecureDht::getCallbackFilter(ValueCallback cb, Value::Filter&& filter) { return [=](const std::vector<Sp<Value>>& values, bool expired) { std::vector<Sp<Value>> tmpvals {}; + if (not filter) + tmpvals.reserve(values.size()); for (const auto& v : values) { if (auto nv = checkValue(v)) if (not filter or filter(*nv)) @@ -301,6 +303,8 @@ SecureDht::getCallbackFilter(GetCallback cb, Value::Filter&& filter) { return [=](const std::vector<Sp<Value>>& values) { std::vector<Sp<Value>> tmpvals {}; + if (not filter) + tmpvals.reserve(values.size()); for (const auto& v : values) { if (auto nv = checkValue(v)) if (not filter or filter(*nv)) diff --git a/src/value.cpp b/src/value.cpp index b21ba41a7016a78d1a5d6296698be76e5e760d73..91bf520ddae62b93c0c6d2040f10c4040c615a47 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -288,7 +288,7 @@ FieldValue::getLocalFilter() const case Value::Field::UserType: return Value::UserTypeFilter(std::string {blobValue.begin(), blobValue.end()}); default: - return Value::AllFilter(); + return {}; } }