trunk/branch integration: optimalization

This commit is contained in:
Marian Krivos
2011-08-23 06:48:43 +00:00
parent 5197acba9e
commit 08d4ebe1cb
2 changed files with 32 additions and 30 deletions

View File

@@ -1,7 +1,7 @@
//
// HexBinaryEncoder.cpp
//
// $Id: //poco/svn/Foundation/src/HexBinaryEncoder.cpp#2 $
// $Id: //poco/1.4/Foundation/src/HexBinaryEncoder.cpp#2 $
//
// Library: Foundation
// Package: Streams
@@ -41,10 +41,10 @@ namespace Poco {
HexBinaryEncoderBuf::HexBinaryEncoderBuf(std::ostream& ostr):
_pos(0),
_lineLength(72),
_uppercase(0),
_ostr(ostr)
_pos(0),
_lineLength(72),
_uppercase(0),
_buf(*ostr.rdbuf())
{
}
@@ -81,24 +81,25 @@ void HexBinaryEncoderBuf::setUppercase(bool flag)
int HexBinaryEncoderBuf::writeToDevice(char c)
{
static const char digits[] = "0123456789abcdef0123456789ABCDEF";
_ostr.put(digits[_uppercase + ((c >> 4) & 0xF)]);
++_pos;
_ostr.put(digits[_uppercase + (c & 0xF)]);
if (++_pos >= _lineLength && _lineLength > 0)
{
_ostr << std::endl;
_pos = 0;
}
return _ostr ? charToInt(c) : -1;
static const int eof = std::char_traits<char>::eof();
static const char digits[] = "0123456789abcdef0123456789ABCDEF";
if (_buf.sputc(digits[_uppercase + ((c >> 4) & 0xF)]) == eof) return eof;
++_pos;
if (_buf.sputc(digits[_uppercase + (c & 0xF)]) == eof) return eof;
if (++_pos >= _lineLength && _lineLength > 0)
{
if (_buf.sputc('\n') == eof) return eof;
_pos = 0;
}
return charToInt(c);
}
int HexBinaryEncoderBuf::close()
{
sync();
_ostr.flush();
return _ostr ? 0 : -1;
sync();
return _buf.pubsync();
}