From 446da4b79227e21f86e963ac0520c44c5aa8d815 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com>
Date: Tue, 29 Nov 2022 21:38:33 -0500
Subject: [PATCH] value: use move in where

---
 include/opendht/value.h | 25 ++++++++++++++-----------
 src/securedht.cpp       |  4 ++--
 2 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/include/opendht/value.h b/include/opendht/value.h
index f4f5daa8..dac624f5 100644
--- a/include/opendht/value.h
+++ b/include/opendht/value.h
@@ -804,11 +804,11 @@ struct OPENDHT_PUBLIC Where
      *
      * @return the resulting Where instance.
      */
-    Where& id(Value::Id id) {
+    Where&& id(Value::Id id) {
         FieldValue fv {Value::Field::Id, id};
         if (std::find(filters_.begin(), filters_.end(), fv) == filters_.end())
             filters_.emplace_back(std::move(fv));
-        return *this;
+        return std::move(*this);
     }
 
     /**
@@ -818,11 +818,11 @@ struct OPENDHT_PUBLIC Where
      *
      * @return the resulting Where instance.
      */
-    Where& valueType(ValueType::Id type) {
+    Where&& valueType(ValueType::Id type) {
         FieldValue fv {Value::Field::ValueType, type};
         if (std::find(filters_.begin(), filters_.end(), fv) == filters_.end())
             filters_.emplace_back(std::move(fv));
-        return *this;
+        return std::move(*this);
     }
 
     /**
@@ -832,11 +832,11 @@ struct OPENDHT_PUBLIC Where
      *
      * @return the resulting Where instance.
      */
-    Where& owner(InfoHash owner_pk_hash) {
+    Where&& owner(InfoHash owner_pk_hash) {
         FieldValue fv {Value::Field::OwnerPk, owner_pk_hash};
         if (std::find(filters_.begin(), filters_.end(), fv) == filters_.end())
             filters_.emplace_back(std::move(fv));
-        return *this;
+        return std::move(*this);
     }
 
     /**
@@ -846,11 +846,11 @@ struct OPENDHT_PUBLIC Where
      *
      * @return the resulting Where instance.
      */
-    Where& seq(uint16_t seq_no) {
+    Where&& seq(uint16_t seq_no) {
         FieldValue fv {Value::Field::SeqNum, seq_no};
         if (std::find(filters_.begin(), filters_.end(), fv) == filters_.end())
             filters_.emplace_back(std::move(fv));
-        return *this;
+        return std::move(*this);
     }
 
     /**
@@ -860,11 +860,11 @@ struct OPENDHT_PUBLIC Where
      *
      * @return the resulting Where instance.
      */
-    Where& userType(std::string_view user_type) {
+    Where&& userType(std::string_view user_type) {
         FieldValue fv {Value::Field::UserType, Blob {user_type.begin(), user_type.end()}};
         if (std::find(filters_.begin(), filters_.end(), fv) == filters_.end())
             filters_.emplace_back(std::move(fv));
-        return *this;
+        return std::move(*this);
     }
 
     /**
@@ -873,7 +873,10 @@ struct OPENDHT_PUBLIC Where
      * @return the resulting Value::Filter.
      */
     Value::Filter getFilter() const {
-        if (filters_.empty()) return {};
+        if (filters_.empty())
+            return {};
+        if (filters_.size() == 1)
+            return filters_[0].getLocalFilter();
         std::vector<Value::Filter> fset;
         fset.reserve(filters_.size());
         for (const auto& f : filters_) {
diff --git a/src/securedht.cpp b/src/securedht.cpp
index 03f9490d..e6ebe0c3 100644
--- a/src/securedht.cpp
+++ b/src/securedht.cpp
@@ -326,7 +326,7 @@ SecureDht::listen(const InfoHash& id, GetCallback cb, Value::Filter f, Where w)
 void
 SecureDht::putSigned(const InfoHash& hash, Sp<Value> val, DoneCallback callback, bool permanent)
 {
-    if (not key_)  {
+    if (not key_ or not hash or not val)  {
         if (callback)
             callback(false, {});
         return;
@@ -365,7 +365,7 @@ SecureDht::putSigned(const InfoHash& hash, Sp<Value> val, DoneCallback callback,
             dht_->put(hash, val, callback, time_point::max(), permanent);
         },
         Value::IdFilter(val->id),
-        std::move(Where().id(val->id))
+        Where().id(val->id)
     );
 }
 
-- 
GitLab