diff options
author | Bernard Normier <bernard@zeroc.com> | 2016-08-05 16:13:47 -0400 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2016-08-05 16:13:47 -0400 |
commit | 71a86f0fcb59a8ea0f4a2e51675630ddaac27a8f (patch) | |
tree | 188156deff284e60491e816af1c2ba06195d0474 /cpp/src/Ice/OutputStream.cpp | |
parent | Fixed type ID for well-known locator registry object (diff) | |
download | ice-71a86f0fcb59a8ea0f4a2e51675630ddaac27a8f.tar.bz2 ice-71a86f0fcb59a8ea0f4a2e51675630ddaac27a8f.tar.xz ice-71a86f0fcb59a8ea0f4a2e51675630ddaac27a8f.zip |
Reduced string converter caching
Diffstat (limited to 'cpp/src/Ice/OutputStream.cpp')
-rw-r--r-- | cpp/src/Ice/OutputStream.cpp | 64 |
1 files changed, 42 insertions, 22 deletions
diff --git a/cpp/src/Ice/OutputStream.cpp b/cpp/src/Ice/OutputStream.cpp index 45d649131fa..4850b0f5474 100644 --- a/cpp/src/Ice/OutputStream.cpp +++ b/cpp/src/Ice/OutputStream.cpp @@ -20,6 +20,7 @@ #include <Ice/TraceUtil.h> #include <Ice/LoggerUtil.h> #include <Ice/SlicedData.h> +#include <Ice/StringConverter.h> #include <iterator> using namespace std; @@ -134,9 +135,6 @@ Ice::OutputStream::initialize(Instance* instance, const EncodingVersion& encodin _instance = instance; _encoding = encoding; - _stringConverter = _instance->getStringConverter(); - _wstringConverter = _instance->getWstringConverter(); - _format = _instance->defaultsAndOverrides()->defaultFormat; } @@ -152,13 +150,6 @@ Ice::OutputStream::clear() } void -Ice::OutputStream::setStringConverters(const StringConverterPtr& sc, const WstringConverterPtr& wsc) -{ - _stringConverter = sc; - _wstringConverter = wsc; -} - -void Ice::OutputStream::setFormat(FormatType fmt) { _format = fmt; @@ -602,11 +593,6 @@ Ice::OutputStream::write(const char*) void Ice::OutputStream::writeConverted(const char* vdata, size_t vsize) { - if(!_stringConverter) - { - throw MarshalException(__FILE__, __LINE__, "no string converter provided"); - } - // // What is the size of the resulting UTF-8 encoded string? // Impossible to tell, so we guess. If we don't guess correctly, @@ -620,7 +606,35 @@ Ice::OutputStream::writeConverted(const char* vdata, size_t vsize) size_t firstIndex = b.size(); StreamUTF8BufferI buffer(*this); - Byte* lastByte = _stringConverter->toUTF8(vdata, vdata + vsize, buffer); + Byte* lastByte = ICE_NULLPTR; + bool converted = false; + if(_instance) + { + const StringConverterPtr& stringConverter = _instance->getStringConverter(); + if(stringConverter) + { + lastByte = stringConverter->toUTF8(vdata, vdata + vsize, buffer); + converted = true; + } + } + else + { + StringConverterPtr stringConverter = getProcessStringConverter(); + if(stringConverter) + { + lastByte = stringConverter->toUTF8(vdata, vdata + vsize, buffer); + converted = true; + } + } + + if(!converted) + { + Container::size_type position = b.size(); + resize(position + vsize); + memcpy(&b[position], vdata, vsize); + return; + } + if(lastByte != b.end()) { resize(lastByte - b.begin()); @@ -691,11 +705,6 @@ Ice::OutputStream::write(const wstring& v) return; } - if(!_wstringConverter) - { - throw MarshalException(__FILE__, __LINE__, "no wstring converter provided"); - } - // // What is the size of the resulting UTF-8 encoded string? // Impossible to tell, so we guess. If we don't guess correctly, @@ -709,7 +718,18 @@ Ice::OutputStream::write(const wstring& v) size_t firstIndex = b.size(); StreamUTF8BufferI buffer(*this); - Byte* lastByte = _wstringConverter->toUTF8(v.data(), v.data() + v.size(), buffer); + Byte* lastByte = ICE_NULLPTR; + + // Note: wstringConverter is never null; when set to null, get returns the default unicode wstring converter + if(_instance) + { + lastByte = _instance->getWstringConverter()->toUTF8(v.data(), v.data() + v.size(), buffer); + } + else + { + lastByte = getProcessWstringConverter()->toUTF8(v.data(), v.data() + v.size(), buffer); + } + if(lastByte != b.end()) { resize(lastByte - b.begin()); |