From 9e60a681f3d86ddc5e8663723aafa866b3157985 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com>
Date: Thu, 16 Mar 2023 16:13:12 -0400
Subject: [PATCH] use ostringstream instead of stringstream where possible

---
 include/opendht/value.h  |  8 ++++----
 src/callbacks.cpp        |  2 +-
 src/dht.cpp              | 12 ++++++------
 src/dht_proxy_server.cpp |  2 +-
 src/dhtrunner.cpp        |  1 +
 src/http.cpp             |  4 ++--
 src/indexation/pht.cpp   |  4 ++--
 src/node.cpp             |  2 +-
 8 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/include/opendht/value.h b/include/opendht/value.h
index 64c52206..ae8776f4 100644
--- a/include/opendht/value.h
+++ b/include/opendht/value.h
@@ -475,7 +475,7 @@ struct OPENDHT_PUBLIC Value
     OPENDHT_PUBLIC friend std::ostream& operator<< (std::ostream& s, const Value& v);
 
     inline std::string toString() const {
-        std::stringstream ss;
+        std::ostringstream ss;
         ss << *this;
         return ss.str();
     }
@@ -774,7 +774,7 @@ struct OPENDHT_PUBLIC Select
     }
 
     std::string toString() const {
-        std::stringstream ss;
+        std::ostringstream ss;
         ss << *this;
         return ss.str();
     }
@@ -897,7 +897,7 @@ struct OPENDHT_PUBLIC Where
     }
 
     std::string toString() const {
-        std::stringstream ss;
+        std::ostringstream ss;
         ss << *this;
         return ss.str();
     }
@@ -963,7 +963,7 @@ struct OPENDHT_PUBLIC Query
     void msgpack_unpack(const msgpack::object& o);
 
     std::string toString() const {
-        std::stringstream ss;
+        std::ostringstream ss;
         ss << *this;
         return ss.str();
     }
diff --git a/src/callbacks.cpp b/src/callbacks.cpp
index ecda4057..b98ab5f9 100644
--- a/src/callbacks.cpp
+++ b/src/callbacks.cpp
@@ -92,7 +92,7 @@ bindDoneCbSimple(DoneCallbackSimpleRaw raw_cb, void* user_data) {
 std::string
 NodeStats::toString() const
 {
-    std::stringstream ss;
+    std::ostringstream ss;
     ss << "Known nodes: " << good_nodes << " good, " << dubious_nodes << " dubious, " << incoming_nodes << " incoming." << std::endl;
     ss << searches << " searches, " << node_cache_size << " total cached nodes" << std::endl;
     if (table_depth > 1) {
diff --git a/src/dht.cpp b/src/dht.cpp
index bcdfb69b..126c6850 100644
--- a/src/dht.cpp
+++ b/src/dht.cpp
@@ -1642,7 +1642,7 @@ Dht::dumpSearch(const Search& sr, std::ostream& out) const
 void
 Dht::dumpTables() const
 {
-    std::stringstream out;
+    std::ostringstream out;
     out << "My id " << myid << std::endl;
 
     out << "Buckets IPv4 :" << std::endl;
@@ -1694,7 +1694,7 @@ Dht::getStorageLog(const InfoHash& h) const
 {
     auto s = store.find(h);
     if (s == store.end()) {
-        std::stringstream out;
+        std::ostringstream out;
         out << "Storage " << h << " empty" << std::endl;
         return out.str();
     }
@@ -1704,7 +1704,7 @@ Dht::getStorageLog(const InfoHash& h) const
 std::string
 Dht::printStorageLog(const decltype(store)::value_type& s) const
 {
-    std::stringstream out;
+    std::ostringstream out;
     using namespace std::chrono;
     const auto& st = s.second;
     out << "Storage " << s.first << " "
@@ -1723,7 +1723,7 @@ Dht::printStorageLog(const decltype(store)::value_type& s) const
 std::string
 Dht::getRoutingTablesLog(sa_family_t af) const
 {
-    std::stringstream out;
+    std::ostringstream out;
     for (const auto& b : buckets(af))
         dumpBucket(b, out);
     return out.str();
@@ -1732,7 +1732,7 @@ Dht::getRoutingTablesLog(sa_family_t af) const
 std::string
 Dht::getSearchesLog(sa_family_t af) const
 {
-    std::stringstream out;
+    std::ostringstream out;
     auto num_searches = dht4.searches.size() + dht6.searches.size();
     if (num_searches > 8) {
         if (not af or af == AF_INET)
@@ -1757,7 +1757,7 @@ Dht::getSearchesLog(sa_family_t af) const
 std::string
 Dht::getSearchLog(const InfoHash& id, sa_family_t af) const
 {
-    std::stringstream out;
+    std::ostringstream out;
     if (af == AF_UNSPEC) {
         out << getSearchLog(id, AF_INET) << getSearchLog(id, AF_INET6);
     } else {
diff --git a/src/dht_proxy_server.cpp b/src/dht_proxy_server.cpp
index 8fd771cc..7ac9a48a 100644
--- a/src/dht_proxy_server.cpp
+++ b/src/dht_proxy_server.cpp
@@ -704,7 +704,7 @@ DhtProxyServer::get(restinio::request_handle_t request,
             initHttpResponse(request->create_response<ResponseByParts>()));
         response->flush();
         dht_->get(infoHash, [this, response](const std::vector<Sp<Value>>& values) {
-            std::stringstream output;
+            std::ostringstream output;
             for (const auto& value : values) {
                 output << Json::writeString(jsonBuilder_, value->toJson()) << "\n";
             }
diff --git a/src/dhtrunner.cpp b/src/dhtrunner.cpp
index f687fdd7..449e0380 100644
--- a/src/dhtrunner.cpp
+++ b/src/dhtrunner.cpp
@@ -1088,6 +1088,7 @@ DhtRunner::setProxyServer(const std::string& proxy, const std::string& pushNodeI
 #else
     if (not proxy.empty())
         throw std::runtime_error("DHT proxy requested but OpenDHT built without proxy support.");
+    (void) pushNodeId;
 #endif
 }
 
diff --git a/src/http.cpp b/src/http.cpp
index 40aca3c0..d7e33bb0 100644
--- a/src/http.cpp
+++ b/src/http.cpp
@@ -87,7 +87,7 @@ Url::Url(const std::string& url): url(url)
 std::string
 Url::toString() const
 {
-    std::stringstream ss;
+    std::ostringstream ss;
     if (not protocol.empty()) {
         ss << protocol << "://";
     }
@@ -1044,7 +1044,7 @@ Request::set_auth(const std::string& username, const std::string& password)
 void
 Request::build()
 {
-    std::stringstream request;
+    std::ostringstream request;
     bool append_body = !body_.empty();
 
     // first header
diff --git a/src/indexation/pht.cpp b/src/indexation/pht.cpp
index 0840c0e3..3aba81d4 100644
--- a/src/indexation/pht.cpp
+++ b/src/indexation/pht.cpp
@@ -32,7 +32,7 @@ namespace indexation {
  * @return string that represent the blob into a readable way
  */
 static std::string blobToString(const Blob &bl) {
-    std::stringstream ss;
+    std::ostringstream ss;
     auto bn = bl.size() % 8;
     auto n = bl.size() / 8;
 
@@ -46,7 +46,7 @@ static std::string blobToString(const Blob &bl) {
 }
 
 std::string Prefix::toString() const {
-    std::stringstream ss;
+    std::ostringstream ss;
 
     ss << "Prefix : " << std::endl << "\tContent_ : \"";
     ss << blobToString(content_);
diff --git a/src/node.cpp b/src/node.cpp
index c444bbe2..e2334ee5 100644
--- a/src/node.cpp
+++ b/src/node.cpp
@@ -160,7 +160,7 @@ Node::closeSocket(Tid id)
 std::string
 Node::toString() const
 {
-    std::stringstream ss;
+    std::ostringstream ss;
     ss << (*this);
     return ss.str();
 }
-- 
GitLab