From 2a99baafdcac46931b00a9ef9e77340dbc319b58 Mon Sep 17 00:00:00 2001 From: Determinant Date: Mon, 14 Oct 2019 13:36:58 -0400 Subject: remove unnecessary std::move() --- include/salticidae/buffer.h | 6 +++--- include/salticidae/conn.h | 2 +- include/salticidae/crypto.h | 10 +++++----- include/salticidae/msg.h | 6 +++--- include/salticidae/netaddr.h | 2 +- include/salticidae/network.h | 2 +- include/salticidae/ref.h | 6 +++--- include/salticidae/stream.h | 10 +++++----- src/conn.cpp | 2 +- src/util.cpp | 4 ++-- test/test_p2p_stress.cpp | 4 +++- 11 files changed, 28 insertions(+), 26 deletions(-) diff --git a/include/salticidae/buffer.h b/include/salticidae/buffer.h index 35d10b8..6d3f97a 100644 --- a/include/salticidae/buffer.h +++ b/include/salticidae/buffer.h @@ -87,7 +87,7 @@ class SegBuffer { auto res = std::move(buffer.front().data); buffer.pop_front(); _size -= res.size(); - return std::move(res); + return res; } bytearray_t pop(size_t len) { @@ -104,7 +104,7 @@ class SegBuffer { } buffer.erase(buffer.begin(), i); _size -= res.size(); - return std::move(res); + return res; } size_t size() const { return _size; } @@ -140,7 +140,7 @@ struct MPSCWriteBuffer { bytearray_t move_pop() { buffer_entry_t res; buffer.try_dequeue(res); - return std::move(res.data); + return res.data; } queue_t &get_queue() { return buffer; } diff --git a/include/salticidae/conn.h b/include/salticidae/conn.h index a594da6..e20a03c 100644 --- a/include/salticidae/conn.h +++ b/include/salticidae/conn.h @@ -563,7 +563,7 @@ class ConnPool { conn = _connect(addr); h.set_result(conn); }).get())); - return std::move(ret); + return ret; } /** Actively connect to remote addr (async). */ diff --git a/include/salticidae/crypto.h b/include/salticidae/crypto.h index fe4de4f..65acc2d 100644 --- a/include/salticidae/crypto.h +++ b/include/salticidae/crypto.h @@ -73,7 +73,7 @@ class SHA256 { bytearray_t digest() { bytearray_t md(32); _digest(md); - return std::move(md); + return md; } }; @@ -115,7 +115,7 @@ class SHA1 { bytearray_t digest() { bytearray_t md(32); _digest(md); - return std::move(md); + return md; } }; @@ -200,7 +200,7 @@ class PKey { bytearray_t res(der, der + ret); OPENSSL_cleanse(der, ret); OPENSSL_free(der); - return std::move(res); + return res; } bytearray_t get_privkey_der() const { @@ -211,7 +211,7 @@ class PKey { bytearray_t res(der, der + ret); OPENSSL_cleanse(der, ret); OPENSSL_free(der); - return std::move(res); + return res; } void save_privkey_to_file(const std::string &fname) { @@ -295,7 +295,7 @@ class X509 { bytearray_t res(der, der + ret); OPENSSL_cleanse(der, ret); OPENSSL_free(der); - return std::move(res); + return res; } void save_to_file(const std::string &fname) { diff --git a/include/salticidae/msg.h b/include/salticidae/msg.h index 670d942..a81a5ae 100644 --- a/include/salticidae/msg.h +++ b/include/salticidae/msg.h @@ -172,7 +172,7 @@ class MsgBase { throw std::runtime_error("payload not available"); no_payload = true; #endif - return std::move(payload); + return DataStream(std::move(payload)); } void set_payload(DataStream &&s) { @@ -203,7 +203,7 @@ class MsgBase { << "checksum=" << get_hex(checksum) << " " #endif << "payload=" << get_hex(payload) << ">"; - return std::move(s); + return std::string(std::move(s)); } #ifndef SALTICIDAE_NOCHECKSUM @@ -239,7 +239,7 @@ class MsgBase { << htole(checksum) #endif << payload; - return std::move(s); + return bytearray_t(std::move(s)); } void gen_hash_list(DataStream &s, diff --git a/include/salticidae/netaddr.h b/include/salticidae/netaddr.h index 7d04d43..669ff27 100644 --- a/include/salticidae/netaddr.h +++ b/include/salticidae/netaddr.h @@ -96,7 +96,7 @@ struct NetAddr { DataStream s; s << ""; - return std::move(s); + return std::string(std::move(s)); } bool is_null() const { return ip == 0 && port == 0; } diff --git a/include/salticidae/network.h b/include/salticidae/network.h index c3b9e79..48b555f 100644 --- a/include/salticidae/network.h +++ b/include/salticidae/network.h @@ -1099,7 +1099,7 @@ PeerNetwork::get_peer_conn(const NetAddr &addr) const { } h.set_result(std::move(conn)); }).get())); - return std::move(ret); + return ret; } template diff --git a/include/salticidae/ref.h b/include/salticidae/ref.h index bb8efc0..bb5fb3a 100644 --- a/include/salticidae/ref.h +++ b/include/salticidae/ref.h @@ -151,7 +151,7 @@ template, typename T_, typename D_> BoxObj static_pointer_cast(BoxObj &&other) { BoxObj box{}; box.obj = static_cast::type *>(other.obj); - return std::move(box); + return box; } struct _RCCtl { @@ -447,7 +447,7 @@ RcObjBase static_pointer_cast(const RcObjBase &other) { rc.obj = static_cast::type *>(other.obj); if ((rc.ctl = other.ctl)) rc.ctl->add_ref(); - return std::move(rc); + return rc; } template, @@ -457,7 +457,7 @@ RcObjBase static_pointer_cast(RcObjBase &&other) { rc.obj = static_cast::type *>(other.obj); rc.ctl = other.ctl; other.ctl = nullptr; - return std::move(rc); + return rc; } template diff --git a/include/salticidae/stream.h b/include/salticidae/stream.h index 251e3f7..fb951cb 100644 --- a/include/salticidae/stream.h +++ b/include/salticidae/stream.h @@ -188,7 +188,7 @@ class DataStream { } operator bytearray_t () && { - return std::move(buffer); + return buffer; } operator std::string () const & { @@ -224,7 +224,7 @@ class Serializable { bytearray_t to_bytes() const { DataStream s; s << *this; - return std::move(s); + return bytearray_t(std::move(s)); } inline std::string to_hex() const; @@ -310,7 +310,7 @@ class Blob: public Serializable { operator bytearray_t () const & { DataStream s; s << *this; - return std::move(s); + return bytearray_t(std::move(s)); } }; @@ -393,7 +393,7 @@ class _Bits { operator bytearray_t () const & { DataStream s; s << *this; - return std::move(s); + return bytearray_t(std::move(s)); } uint8_t get(uint32_t idx) const { @@ -453,7 +453,7 @@ template inline std::string get_hex(const T &x) { inline bytearray_t from_hex(const std::string &hex_str) { DataStream s; s.load_hex(hex_str); - return std::move(s); + return bytearray_t(std::move(s)); } inline std::string Serializable::to_hex() const { return get_hex(*this); } diff --git a/src/conn.cpp b/src/conn.cpp index 15f90bc..dab10dc 100644 --- a/src/conn.cpp +++ b/src/conn.cpp @@ -47,7 +47,7 @@ ConnPool::Conn::operator std::string() const { case Conn::PASSIVE: s << "passive"; break; } s << ">"; - return std::move(s); + return std::string(std::move(s)); } /* the following functions are executed by exactly one worker per Conn object */ diff --git a/src/util.cpp b/src/util.cpp index 19b6915..ce98b22 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -126,7 +126,7 @@ std::string vstringprintf(const char *fmt, va_list _ap) { } } va_end(ap); - return std::move(buff); + return buff; } std::string stringprintf(const char *fmt, ...) { @@ -134,7 +134,7 @@ std::string stringprintf(const char *fmt, ...) { va_start(ap, fmt); auto ret = vstringprintf(fmt, ap); va_end(ap); - return std::move(ret); + return ret; } const std::string get_current_datetime() { diff --git a/test/test_p2p_stress.cpp b/test/test_p2p_stress.cpp index 49f1b2e..e4341bb 100644 --- a/test/test_p2p_stress.cpp +++ b/test/test_p2p_stress.cpp @@ -151,7 +151,9 @@ void install_proto(AppContext &app, const size_t &seg_buff_size) { } if (msg.hash != tc.hash) { - SALTICIDAE_LOG_ERROR("corrupted I/O!"); + SALTICIDAE_LOG_ERROR("%s corrupted I/O: from=%s view=%d state=%d", + std::string(app.addr).c_str(), + std::string(addr).c_str(), msg.view, tc.state); exit(1); } -- cgit v1.2.3