diff options
author | Mark Spruiell <mes@zeroc.com> | 2006-08-24 22:35:42 +0000 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2006-08-24 22:35:42 +0000 |
commit | cde3ecbeeacd5d9eda4a5982bc744b5df57f3f60 (patch) | |
tree | fa47b95ddcc9113c3de1f5a7fe282765cd88f500 /cpp/src/Ice/BasicStream.cpp | |
parent | bug 1156: removing deprecated Identity properties (diff) | |
download | ice-cde3ecbeeacd5d9eda4a5982bc744b5df57f3f60.tar.bz2 ice-cde3ecbeeacd5d9eda4a5982bc744b5df57f3f60.tar.xz ice-cde3ecbeeacd5d9eda4a5982bc744b5df57f3f60.zip |
bug 1318: modify zero-copy API
Diffstat (limited to 'cpp/src/Ice/BasicStream.cpp')
-rw-r--r-- | cpp/src/Ice/BasicStream.cpp | 99 |
1 files changed, 54 insertions, 45 deletions
diff --git a/cpp/src/Ice/BasicStream.cpp b/cpp/src/Ice/BasicStream.cpp index b8c7f12b659..3f75b9296a4 100644 --- a/cpp/src/Ice/BasicStream.cpp +++ b/cpp/src/Ice/BasicStream.cpp @@ -542,8 +542,7 @@ namespace template<size_t boolSize> struct BasicStreamReadBoolHelper { - static void read(pair<const bool*, const bool*>& v, IceUtil::auto_array<bool>& b, - Int sz, BasicStream::Container::iterator& i) + static bool* read(pair<const bool*, const bool*>& v, Int sz, BasicStream::Container::iterator& i) { bool* array = new bool[sz]; for(int idx = 0; idx < sz; ++idx) @@ -552,38 +551,40 @@ struct BasicStreamReadBoolHelper } v.first = array; v.second = array + sz; - b.reset(array); + return array; } }; template<> struct BasicStreamReadBoolHelper<1> { - static void read(pair<const bool*, const bool*>& v, IceUtil::auto_array<bool>& b, - Int sz, BasicStream::Container::iterator& i) + static bool* read(pair<const bool*, const bool*>& v, Int sz, BasicStream::Container::iterator& i) { v.first = reinterpret_cast<bool*>(i); v.second = reinterpret_cast<bool*>(i) + sz; + return 0; } }; } -void -IceInternal::BasicStream::read(pair<const bool*, const bool*>& v, IceUtil::auto_array<bool>& b) +bool* +IceInternal::BasicStream::read(pair<const bool*, const bool*>& v) { + bool* result = 0; Int sz; readSize(sz); if(sz > 0) { checkFixedSeq(sz, 1); - BasicStreamReadBoolHelper<sizeof(bool)>::read(v, b, sz, i); + result = BasicStreamReadBoolHelper<sizeof(bool)>::read(v, sz, i); i += sz; } else { v.first = v.second = reinterpret_cast<bool*>(i); } + return result; } void @@ -677,9 +678,10 @@ IceInternal::BasicStream::read(vector<Short>& v) } } -void -IceInternal::BasicStream::read(pair<const Short*, const Short*>& v, IceUtil::auto_array<Short>& b) +Short* +IceInternal::BasicStream::read(pair<const Short*, const Short*>& v) { + Short* result = 0; Int sz; readSize(sz); if(sz > 0) @@ -690,16 +692,15 @@ IceInternal::BasicStream::read(pair<const Short*, const Short*>& v, IceUtil::aut i += sz * static_cast<int>(sizeof(Short)); v.second = reinterpret_cast<Short*>(i); #else - Short* array = new Short[sz]; - v.first = array; - v.second = array + sz; - b.reset(array); + result = new Short[sz]; + v.first = result; + v.second = result + sz; Container::iterator begin = i; i += sz * static_cast<int>(sizeof(Short)); # ifdef ICE_BIG_ENDIAN const Byte* src = &(*begin); - Byte* dest = reinterpret_cast<Byte*>(&array[0]) + sizeof(Short) - 1; + Byte* dest = reinterpret_cast<Byte*>(&result[0]) + sizeof(Short) - 1; for(int j = 0 ; j < sz ; ++j) { *dest-- = *src++; @@ -707,7 +708,7 @@ IceInternal::BasicStream::read(pair<const Short*, const Short*>& v, IceUtil::aut dest += 2 * sizeof(Short); } # else - copy(begin, i, reinterpret_cast<Byte*>(&array[0])); + copy(begin, i, reinterpret_cast<Byte*>(&result[0])); # endif #endif } @@ -715,6 +716,7 @@ IceInternal::BasicStream::read(pair<const Short*, const Short*>& v, IceUtil::aut { v.first = v.second = 0; } + return result; } void @@ -775,9 +777,10 @@ IceInternal::BasicStream::read(vector<Int>& v) } } -void -IceInternal::BasicStream::read(pair<const Int*, const Int*>& v, IceUtil::auto_array<Int>& b) +Int* +IceInternal::BasicStream::read(pair<const Int*, const Int*>& v) { + Int* result = 0; Int sz; readSize(sz); if(sz > 0) @@ -788,16 +791,15 @@ IceInternal::BasicStream::read(pair<const Int*, const Int*>& v, IceUtil::auto_ar i += sz * static_cast<int>(sizeof(Int)); v.second = reinterpret_cast<Int*>(i); #else - Int* array = new Int[sz]; - v.first = array; - v.second = array + sz; - b.reset(array); + result = new Int[sz]; + v.first = result; + v.second = result + sz; Container::iterator begin = i; i += sz * static_cast<int>(sizeof(Int)); # ifdef ICE_BIG_ENDIAN const Byte* src = &(*begin); - Byte* dest = reinterpret_cast<Byte*>(&array[0]) + sizeof(Int) - 1; + Byte* dest = reinterpret_cast<Byte*>(&result[0]) + sizeof(Int) - 1; for(int j = 0 ; j < sz ; ++j) { *dest-- = *src++; @@ -807,7 +809,7 @@ IceInternal::BasicStream::read(pair<const Int*, const Int*>& v, IceUtil::auto_ar dest += 2 * sizeof(Int); } # else - copy(begin, i, reinterpret_cast<Byte*>(&array[0])); + copy(begin, i, reinterpret_cast<Byte*>(&result[0])); # endif #endif } @@ -815,6 +817,7 @@ IceInternal::BasicStream::read(pair<const Int*, const Int*>& v, IceUtil::auto_ar { v.first = v.second = 0; } + return result; } void @@ -944,9 +947,10 @@ IceInternal::BasicStream::read(vector<Long>& v) } } -void -IceInternal::BasicStream::read(pair<const Long*, const Long*>& v, IceUtil::auto_array<Long>& b) +Long* +IceInternal::BasicStream::read(pair<const Long*, const Long*>& v) { + Long* result = 0; Int sz; readSize(sz); if(sz > 0) @@ -957,16 +961,16 @@ IceInternal::BasicStream::read(pair<const Long*, const Long*>& v, IceUtil::auto_ i += sz * static_cast<int>(sizeof(Long)); v.second = reinterpret_cast<Long*>(i); #else - Long* array = new Long[sz]; - v.first = array; - v.second = array + sz; + result = new Long[sz]; + v.first = result; + v.second = result + sz; b.reset(array); Container::iterator begin = i; i += sz * static_cast<int>(sizeof(Long)); # ifdef ICE_BIG_ENDIAN const Byte* src = &(*begin); - Byte* dest = reinterpret_cast<Byte*>(&array[0]) + sizeof(Long) - 1; + Byte* dest = reinterpret_cast<Byte*>(&result[0]) + sizeof(Long) - 1; for(int j = 0 ; j < sz ; ++j) { *dest-- = *src++; @@ -980,7 +984,7 @@ IceInternal::BasicStream::read(pair<const Long*, const Long*>& v, IceUtil::auto_ dest += 2 * sizeof(Long); } # else - copy(begin, i, reinterpret_cast<Byte*>(&array[0])); + copy(begin, i, reinterpret_cast<Byte*>(&result[0])); # endif #endif } @@ -988,6 +992,7 @@ IceInternal::BasicStream::read(pair<const Long*, const Long*>& v, IceUtil::auto_ { v.first = v.second = 0; } + return result; } void @@ -1093,9 +1098,10 @@ IceInternal::BasicStream::read(vector<Float>& v) } } -void -IceInternal::BasicStream::read(pair<const Float*, const Float*>& v, IceUtil::auto_array<Float>& b) +Float* +IceInternal::BasicStream::read(pair<const Float*, const Float*>& v) { + Float* result = 0; Int sz; readSize(sz); if(sz > 0) @@ -1106,16 +1112,16 @@ IceInternal::BasicStream::read(pair<const Float*, const Float*>& v, IceUtil::aut i += sz * static_cast<int>(sizeof(Float)); v.second = reinterpret_cast<Float*>(i); #else - Float* array = new Float[sz]; - v.first = array; - v.second = array + sz; + result = new Float[sz]; + v.first = result; + v.second = result + sz; b.reset(array); Container::iterator begin = i; i += sz * static_cast<int>(sizeof(Float)); # ifdef ICE_BIG_ENDIAN const Byte* src = &(*begin); - Byte* dest = reinterpret_cast<Byte*>(&array[0]) + sizeof(Float) - 1; + Byte* dest = reinterpret_cast<Byte*>(&result[0]) + sizeof(Float) - 1; for(int j = 0 ; j < sz ; ++j) { *dest-- = *src++; @@ -1125,7 +1131,7 @@ IceInternal::BasicStream::read(pair<const Float*, const Float*>& v, IceUtil::aut dest += 2 * sizeof(Float); } # else - copy(begin, i, reinterpret_cast<Byte*>(&array[0])); + copy(begin, i, reinterpret_cast<Byte*>(&result[0])); # endif #endif } @@ -1133,6 +1139,7 @@ IceInternal::BasicStream::read(pair<const Float*, const Float*>& v, IceUtil::aut { v.first = v.second = 0; } + return result; } void @@ -1262,9 +1269,10 @@ IceInternal::BasicStream::read(vector<Double>& v) } } -void -IceInternal::BasicStream::read(pair<const Double*, const Double*>& v, IceUtil::auto_array<Double>& b) +Double* +IceInternal::BasicStream::read(pair<const Double*, const Double*>& v) { + Double* result = 0; Int sz; readSize(sz); if(sz > 0) @@ -1275,16 +1283,16 @@ IceInternal::BasicStream::read(pair<const Double*, const Double*>& v, IceUtil::a i += sz * static_cast<int>(sizeof(Double)); v.second = reinterpret_cast<Double*>(i); #else - Double* array = new Double[sz]; - v.first = array; - v.second = array + sz; + result = new Double[sz]; + v.first = result; + v.second = result + sz; b.reset(array); Container::iterator begin = i; i += sz * static_cast<int>(sizeof(Double)); # ifdef ICE_BIG_ENDIAN const Byte* src = &(*begin); - Byte* dest = reinterpret_cast<Byte*>(&array[0]) + sizeof(Double) - 1; + Byte* dest = reinterpret_cast<Byte*>(&result[0]) + sizeof(Double) - 1; for(int j = 0 ; j < sz ; ++j) { *dest-- = *src++; @@ -1298,7 +1306,7 @@ IceInternal::BasicStream::read(pair<const Double*, const Double*>& v, IceUtil::a dest += 2 * sizeof(Double); } # else - copy(begin, i, reinterpret_cast<Byte*>(&array[0])); + copy(begin, i, reinterpret_cast<Byte*>(&result[0])); # endif #endif } @@ -1306,6 +1314,7 @@ IceInternal::BasicStream::read(pair<const Double*, const Double*>& v, IceUtil::a { v.first = v.second = 0; } + return result; } // |