summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/tests/stllike/asciistream_test.cpp19
-rw-r--r--vespalib/src/vespa/vespalib/net/tls/impl/openssl_tls_context_impl.cpp4
-rw-r--r--vespalib/src/vespa/vespalib/stllike/asciistream.cpp29
-rw-r--r--vespalib/src/vespa/vespalib/stllike/asciistream.h6
4 files changed, 51 insertions, 7 deletions
diff --git a/vespalib/src/tests/stllike/asciistream_test.cpp b/vespalib/src/tests/stllike/asciistream_test.cpp
index 955edc25d7e..2c89bab75fa 100644
--- a/vespalib/src/tests/stllike/asciistream_test.cpp
+++ b/vespalib/src/tests/stllike/asciistream_test.cpp
@@ -23,6 +23,7 @@ public:
void testWriteThenRead();
void testGetLine();
void testCopyConstruct();
+ void testMoveIsWellDefined();
void testIllegalNumbers();
void testDouble();
void testStateSaver();
@@ -169,6 +170,23 @@ AsciistreamTest::testCopyConstruct()
}
void
+AsciistreamTest::testMoveIsWellDefined()
+{
+ asciistream read_only("hello world");
+ asciistream dest(std::move(read_only));
+ EXPECT_EQUAL("hello world", dest.str());
+
+ read_only = asciistream("a string long enough to not be short string optimized");
+ dest = std::move(read_only);
+ EXPECT_EQUAL("a string long enough to not be short string optimized", dest.str());
+
+ asciistream written_src;
+ written_src << "a foo walks into a bar";
+ dest = std::move(written_src);
+ EXPECT_EQUAL("a foo walks into a bar", dest.str());
+}
+
+void
AsciistreamTest::testIntegerManip()
{
asciistream os;
@@ -518,6 +536,7 @@ AsciistreamTest::Main()
TEST_DO(verifyBothWays<uint64_t>(7, "7"));
testCopyConstruct();
+ testMoveIsWellDefined();
testIntegerManip();
testFill();
testString();
diff --git a/vespalib/src/vespa/vespalib/net/tls/impl/openssl_tls_context_impl.cpp b/vespalib/src/vespa/vespalib/net/tls/impl/openssl_tls_context_impl.cpp
index fb29af21ea8..130847b49a7 100644
--- a/vespalib/src/vespa/vespalib/net/tls/impl/openssl_tls_context_impl.cpp
+++ b/vespalib/src/vespa/vespalib/net/tls/impl/openssl_tls_context_impl.cpp
@@ -411,9 +411,9 @@ int OpenSslTlsContextImpl::verify_cb_wrapper(int preverified_ok, ::X509_STORE_CT
return 1; // OK for root/intermediate cert. Callback will be invoked again for other certs.
}
// Fetch the SSL instance associated with the X509_STORE_CTX
- const void* data = ::X509_STORE_CTX_get_ex_data(store_ctx, ::SSL_get_ex_data_X509_STORE_CTX_idx());
+ void* data = ::X509_STORE_CTX_get_ex_data(store_ctx, ::SSL_get_ex_data_X509_STORE_CTX_idx());
LOG_ASSERT(data != nullptr);
- const auto* ssl = static_cast<const ::SSL*>(data);
+ auto* ssl = static_cast<::SSL*>(data);
const ::SSL_CTX* ssl_ctx = ::SSL_get_SSL_CTX(ssl);
LOG_ASSERT(ssl_ctx != nullptr);
auto* self = static_cast<OpenSslTlsContextImpl*>(SSL_CTX_get_app_data(ssl_ctx));
diff --git a/vespalib/src/vespa/vespalib/stllike/asciistream.cpp b/vespalib/src/vespa/vespalib/stllike/asciistream.cpp
index 9b2cdad822a..35f7b0e1be7 100644
--- a/vespalib/src/vespa/vespalib/stllike/asciistream.cpp
+++ b/vespalib/src/vespa/vespalib/stllike/asciistream.cpp
@@ -102,17 +102,42 @@ asciistream & asciistream::operator = (const asciistream & rhs)
return *this;
}
-void asciistream::swap(asciistream & rhs)
+asciistream::asciistream(asciistream && rhs) noexcept
+ : asciistream()
+{
+ swap(rhs);
+}
+
+asciistream & asciistream::operator = (asciistream && rhs) noexcept
+{
+ if (this != &rhs) {
+ swap(rhs);
+ }
+ return *this;
+}
+
+void asciistream::swap(asciistream & rhs) noexcept
{
std::swap(_rPos, rhs._rPos);
+ // If read-only, _wbuf is empty and _rbuf is set
+ // If ever written to, _rbuf == _wbuf
+ const bool lhs_read_only = (_rbuf.data() != _wbuf.data());
+ const bool rhs_read_only = (rhs._rbuf.data() != rhs._wbuf.data());
std::swap(_wbuf, rhs._wbuf);
+ std::swap(_rbuf, rhs._rbuf);
+ if (!lhs_read_only) {
+ rhs._rbuf = rhs._wbuf;
+ }
+ if (!rhs_read_only) {
+ _rbuf = _wbuf;
+ }
+
std::swap(_base, rhs._base);
std::swap(_floatSpec, rhs._floatSpec);
std::swap(_floatModifier, rhs._floatModifier);
std::swap(_width, rhs._width);
std::swap(_precision, rhs._precision);
std::swap(_fill, rhs._fill);
- _rbuf = _wbuf;
}
namespace {
diff --git a/vespalib/src/vespa/vespalib/stllike/asciistream.h b/vespalib/src/vespa/vespalib/stllike/asciistream.h
index c225c371a78..428ed983e16 100644
--- a/vespalib/src/vespa/vespalib/stllike/asciistream.h
+++ b/vespalib/src/vespa/vespalib/stllike/asciistream.h
@@ -35,9 +35,9 @@ public:
~asciistream();
asciistream(const asciistream & rhs);
asciistream & operator = (const asciistream & rhs);
- asciistream(asciistream &&) = default;
- asciistream & operator = (asciistream &&) = default;
- void swap(asciistream & rhs);
+ asciistream(asciistream &&) noexcept;
+ asciistream & operator = (asciistream &&) noexcept;
+ void swap(asciistream & rhs) noexcept;
asciistream & operator << (bool v) { if (v) { *this << '1'; } else { *this << '0'; } return *this; }
asciistream & operator << (char v) { doFill(1); write(&v, 1); return *this; }
asciistream & operator << (unsigned char v) { doFill(1); write(&v, 1); return *this; }