Skip to content

Commit

Permalink
Add move ctor and assignment operator to InputStream (#2092)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier authored May 15, 2024
1 parent 484a29d commit e349f8b
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 4 deletions.
12 changes: 12 additions & 0 deletions cpp/include/Ice/InputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,18 @@ namespace Ice
InputStream(const CommunicatorPtr&, const EncodingVersion&, IceInternal::Buffer&, bool = false);
/// \endcond

/**
* Move constructor.
* @param other The input stream to move into this input stream.
*/
InputStream(InputStream&& other) noexcept;

/**
* Move assignment operator.
* @param other The input stream to move into this input stream.
*/
InputStream& operator=(InputStream&& other) noexcept;

~InputStream()
{
// Inlined for performance reasons.
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/ConnectionI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3283,7 +3283,7 @@ Ice::ConnectionI::parseMessage(int32_t& upcallCount, function<bool(InputStream&)
}

// The message stream is adopted by the outgoing.
stream.swap(*outAsync->getIs());
*outAsync->getIs() = std::move(stream);

#if defined(ICE_USE_IOCP)
//
Expand Down
54 changes: 51 additions & 3 deletions cpp/src/Ice/InputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,54 @@ Ice::InputStream::InputStream(Instance* instance, const EncodingVersion& encodin
initialize(instance, encoding);
}

Ice::InputStream::InputStream(InputStream&& other) noexcept
: Buffer(std::move(other)),
_instance(other._instance),
_encoding(std::move(other._encoding)),
_traceSlicing(other._traceSlicing),
_classGraphDepthMax(other._classGraphDepthMax),
_closure(other._closure),
_sliceValues(other._sliceValues),
_startSeq(other._startSeq),
_minSeqSize(other._minSeqSize),
_valueFactoryManager(std::move(other._valueFactoryManager)),
_logger(std::move(other._logger)),
_compactIdResolver(std::move(other._compactIdResolver))
{
resetEncapsulation();

// Reset other to its default state
other.resetEncapsulation();
other.initialize(currentEncoding);
}

InputStream&
Ice::InputStream::operator=(InputStream&& other) noexcept
{
if (this != &other)
{
Buffer::operator=(std::move(other));
_instance = other._instance;
_encoding = std::move(other._encoding);
_traceSlicing = other._traceSlicing;
_classGraphDepthMax = other._classGraphDepthMax;
_closure = other._closure;
_sliceValues = other._sliceValues;
_startSeq = other._startSeq;
_minSeqSize = other._minSeqSize;
_valueFactoryManager = std::move(other._valueFactoryManager);
_logger = std::move(other._logger);
_compactIdResolver = std::move(other._compactIdResolver);

resetEncapsulation();

// Reset other to its default state.
other.resetEncapsulation();
other.initialize(currentEncoding);
}
return *this;
}

void
Ice::InputStream::initialize(const CommunicatorPtr& communicator)
{
Expand All @@ -152,12 +200,12 @@ Ice::InputStream::initialize(Instance* instance, const EncodingVersion& encoding
void
Ice::InputStream::initialize(const EncodingVersion& encoding)
{
_instance = 0;
_instance = nullptr;
_encoding = encoding;
_currentEncaps = 0;
_currentEncaps = nullptr;
_traceSlicing = false;
_classGraphDepthMax = 0x7fffffff;
_closure = 0;
_closure = nullptr;
_sliceValues = true;
_startSeq = -1;
_minSeqSize = 0;
Expand Down

0 comments on commit e349f8b

Please sign in to comment.