mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-28 19:51:58 +01:00
avoid redundant strlen.
This commit is contained in:
@@ -189,6 +189,8 @@ private:
|
|||||||
while (value);
|
while (value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BinaryWriter& write(const char* value, std::size_t length);
|
||||||
|
|
||||||
std::ostream& _ostr;
|
std::ostream& _ostr;
|
||||||
bool _flipBytes;
|
bool _flipBytes;
|
||||||
TextConverter* _pTextConverter;
|
TextConverter* _pTextConverter;
|
||||||
|
|||||||
@@ -153,29 +153,13 @@ BinaryWriter& BinaryWriter::operator << (UInt64 value)
|
|||||||
|
|
||||||
BinaryWriter& BinaryWriter::operator << (const std::string& value)
|
BinaryWriter& BinaryWriter::operator << (const std::string& value)
|
||||||
{
|
{
|
||||||
return *this << value.c_str();
|
return write(value.c_str(), value.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BinaryWriter& BinaryWriter::operator << (const char* value)
|
BinaryWriter& BinaryWriter::operator << (const char* value)
|
||||||
{
|
{
|
||||||
poco_check_ptr (value);
|
return write(value, std::strlen(value));
|
||||||
|
|
||||||
if (_pTextConverter)
|
|
||||||
{
|
|
||||||
std::string converted;
|
|
||||||
_pTextConverter->convert(value, static_cast<int>(std::strlen(value)), converted);
|
|
||||||
UInt32 length = (UInt32) converted.size();
|
|
||||||
write7BitEncoded(length);
|
|
||||||
_ostr.write(converted.data(), length);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
UInt32 length = static_cast<UInt32>(std::strlen(value));
|
|
||||||
write7BitEncoded(length);
|
|
||||||
_ostr.write(value, length);
|
|
||||||
}
|
|
||||||
return *this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -223,4 +207,26 @@ void BinaryWriter::flush()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BinaryWriter& BinaryWriter::write(const char* value, std::size_t length)
|
||||||
|
{
|
||||||
|
poco_check_ptr (value);
|
||||||
|
|
||||||
|
if (_pTextConverter)
|
||||||
|
{
|
||||||
|
std::string converted;
|
||||||
|
_pTextConverter->convert(value, static_cast<int>(length), converted);
|
||||||
|
UInt32 convertedLength = (UInt32) converted.length();
|
||||||
|
write7BitEncoded(convertedLength);
|
||||||
|
_ostr.write(converted.data(), convertedLength);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UInt32 lengthUInt32 = static_cast<UInt32>(length);
|
||||||
|
write7BitEncoded(lengthUInt32);
|
||||||
|
_ostr.write(value, lengthUInt32);
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|||||||
Reference in New Issue
Block a user