summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorMarc Laukien <marc@zeroc.com>2005-02-03 19:59:54 +0000
committerMarc Laukien <marc@zeroc.com>2005-02-03 19:59:54 +0000
commitb7ed2d83e9e488d4b533e0042ac912e9afe248b7 (patch)
tree0d90033f01b5568b426929370fce9b002b5ecec7 /cpp/src
parentDisable connection management for demo (diff)
downloadice-b7ed2d83e9e488d4b533e0042ac912e9afe248b7.tar.bz2
ice-b7ed2d83e9e488d4b533e0042ac912e9afe248b7.tar.xz
ice-b7ed2d83e9e488d4b533e0042ac912e9afe248b7.zip
encaps optimizations
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Ice/BasicStream.cpp152
1 files changed, 140 insertions, 12 deletions
diff --git a/cpp/src/Ice/BasicStream.cpp b/cpp/src/Ice/BasicStream.cpp
index 4fac52e40a5..6e4a527305c 100644
--- a/cpp/src/Ice/BasicStream.cpp
+++ b/cpp/src/Ice/BasicStream.cpp
@@ -58,14 +58,14 @@ IceInternal::BasicStream::BasicStream(Instance* instance) :
IceInternal::BasicStream::~BasicStream()
{
- while(_currentReadEncaps)
+ while(_currentReadEncaps && _currentReadEncaps != &_preAllocatedReadEncaps)
{
ReadEncaps* oldEncaps = _currentReadEncaps;
_currentReadEncaps = _currentReadEncaps->previous;
delete oldEncaps;
}
- while(_currentWriteEncaps)
+ while(_currentWriteEncaps && _currentWriteEncaps != &_preAllocatedWriteEncaps)
{
WriteEncaps* oldEncaps = _currentWriteEncaps;
_currentWriteEncaps = _currentWriteEncaps->previous;
@@ -95,8 +95,48 @@ IceInternal::BasicStream::swap(BasicStream& other)
b.swap(other.b);
std::swap(i, other.i);
- std::swap(_currentReadEncaps, other._currentReadEncaps);
- std::swap(_currentWriteEncaps, other._currentWriteEncaps);
+
+ //
+ // Swap is never called for BasicStreams that have more than one
+ // encaps.
+ //
+ assert(!_currentReadEncaps || _currentReadEncaps == &_preAllocatedReadEncaps);
+ assert(!_currentWriteEncaps || _currentWriteEncaps == &_preAllocatedWriteEncaps);
+ assert(!other._currentReadEncaps || other._currentReadEncaps == &other._preAllocatedReadEncaps);
+ assert(!other._currentWriteEncaps || other._currentWriteEncaps == &other._preAllocatedWriteEncaps);
+
+ if(_currentReadEncaps || other._currentReadEncaps)
+ {
+ _preAllocatedReadEncaps.swap(other._preAllocatedReadEncaps);
+
+ if(!_currentReadEncaps)
+ {
+ _currentReadEncaps = &_preAllocatedReadEncaps;
+ other._currentReadEncaps = 0;
+ }
+ else if(!other._currentReadEncaps)
+ {
+ other._currentReadEncaps = &other._preAllocatedReadEncaps;
+ _currentReadEncaps = 0;
+ }
+ }
+
+ if(_currentWriteEncaps || other._currentWriteEncaps)
+ {
+ _preAllocatedWriteEncaps.swap(other._preAllocatedWriteEncaps);
+
+ if(!_currentWriteEncaps)
+ {
+ _currentWriteEncaps = &_preAllocatedWriteEncaps;
+ other._currentWriteEncaps = 0;
+ }
+ else if(!other._currentWriteEncaps)
+ {
+ other._currentWriteEncaps = &other._preAllocatedWriteEncaps;
+ _currentWriteEncaps = 0;
+ }
+ }
+
std::swap(_seqDataStack, other._seqDataStack);
std::swap(_objectList, other._objectList);
}
@@ -250,11 +290,47 @@ IceInternal::BasicStream::WriteEncaps::~WriteEncaps()
}
void
+IceInternal::BasicStream::WriteEncaps::reset()
+{
+ delete toBeMarshaledMap;
+ delete marshaledMap;
+ delete typeIdMap;
+
+ writeIndex = 0;
+ toBeMarshaledMap = 0;
+ marshaledMap = 0;
+ typeIdMap = 0;
+ typeIdIndex = 0;
+ previous = 0;
+}
+
+void
+IceInternal::BasicStream::WriteEncaps::swap(WriteEncaps& other)
+{
+ std::swap(start, other.start);
+
+ std::swap(writeIndex, other.writeIndex);
+ std::swap(toBeMarshaledMap, other.toBeMarshaledMap);
+ std::swap(marshaledMap, other.marshaledMap);
+ std::swap(typeIdMap, other.typeIdMap);
+ std::swap(typeIdIndex, other.typeIdIndex);
+
+ std::swap(previous, other.previous);
+}
+
+void
IceInternal::BasicStream::startWriteEncaps()
{
WriteEncaps* oldEncaps = _currentWriteEncaps;
- _currentWriteEncaps = new WriteEncaps();
- _currentWriteEncaps->previous = oldEncaps;
+ if(!oldEncaps) // First allocated encaps?
+ {
+ _currentWriteEncaps = &_preAllocatedWriteEncaps;
+ }
+ else
+ {
+ _currentWriteEncaps = new WriteEncaps();
+ _currentWriteEncaps->previous = oldEncaps;
+ }
_currentWriteEncaps->start = b.size();
write(Int(0)); // Placeholder for the encapsulation length.
@@ -286,7 +362,14 @@ IceInternal::BasicStream::endWriteEncaps()
WriteEncaps* oldEncaps = _currentWriteEncaps;
_currentWriteEncaps = _currentWriteEncaps->previous;
- delete oldEncaps;
+ if(oldEncaps == &_preAllocatedWriteEncaps)
+ {
+ oldEncaps->reset();
+ }
+ else
+ {
+ delete oldEncaps;
+ }
}
IceInternal::BasicStream::ReadEncaps::ReadEncaps()
@@ -302,11 +385,49 @@ IceInternal::BasicStream::ReadEncaps::~ReadEncaps()
}
void
+IceInternal::BasicStream::ReadEncaps::reset()
+{
+ delete patchMap;
+ delete unmarshaledMap;
+ delete typeIdMap;
+
+ patchMap = 0;
+ unmarshaledMap = 0;
+ typeIdMap = 0;
+ typeIdIndex = 0;
+ previous = 0;
+}
+
+void
+IceInternal::BasicStream::ReadEncaps::swap(ReadEncaps& other)
+{
+ std::swap(start, other.start);
+ std::swap(sz, other.sz);
+
+ std::swap(encodingMajor, other.encodingMajor);
+ std::swap(encodingMinor, other.encodingMinor);
+
+ std::swap(patchMap, other.patchMap);
+ std::swap(unmarshaledMap, other.unmarshaledMap);
+ std::swap(typeIdMap, other.typeIdMap);
+ std::swap(typeIdIndex, other.typeIdIndex);
+
+ std::swap(previous, other.previous);
+}
+
+void
IceInternal::BasicStream::startReadEncaps()
{
ReadEncaps* oldEncaps = _currentReadEncaps;
- _currentReadEncaps = new ReadEncaps();
- _currentReadEncaps->previous = oldEncaps;
+ if(!oldEncaps) // First allocated encaps?
+ {
+ _currentReadEncaps = &_preAllocatedReadEncaps;
+ }
+ else
+ {
+ _currentReadEncaps = new ReadEncaps();
+ _currentReadEncaps->previous = oldEncaps;
+ }
_currentReadEncaps->start = i - b.begin();
//
@@ -356,7 +477,14 @@ IceInternal::BasicStream::endReadEncaps()
ReadEncaps* oldEncaps = _currentReadEncaps;
_currentReadEncaps = _currentReadEncaps->previous;
- delete oldEncaps;
+ if(oldEncaps == &_preAllocatedReadEncaps)
+ {
+ oldEncaps->reset();
+ }
+ else
+ {
+ delete oldEncaps;
+ }
}
void
@@ -1260,7 +1388,7 @@ IceInternal::BasicStream::write(const ObjectPtr& v)
{
if(!_currentWriteEncaps) // Lazy initialization.
{
- _currentWriteEncaps = new WriteEncaps();
+ _currentWriteEncaps = &_preAllocatedWriteEncaps;
_currentWriteEncaps->start = b.size();
}
@@ -1312,7 +1440,7 @@ IceInternal::BasicStream::read(PatchFunc patchFunc, void* patchAddr)
{
if(!_currentReadEncaps) // Lazy initialization.
{
- _currentReadEncaps = new ReadEncaps();
+ _currentReadEncaps = &_preAllocatedReadEncaps;
}
if(!_currentReadEncaps->patchMap) // Lazy initialization.