Kaydet (Commit) 5fcfa368 authored tarafından Caolán McNamara's avatar Caolán McNamara

ofz#3577: speed up short reads

Change-Id: Ic05a7eb415ca0d3ee1cef5dcf0a881119bf52ac6
Reviewed-on: https://gerrit.libreoffice.org/43276Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst bcde9f1b
...@@ -273,13 +273,12 @@ OUString SfxOleStringHelper::ImplLoadString8( SvStream& rStrm ) const ...@@ -273,13 +273,12 @@ OUString SfxOleStringHelper::ImplLoadString8( SvStream& rStrm ) const
DBG_ASSERT( (0 < nSize) && (nSize <= 0xFFFF), DBG_ASSERT( (0 < nSize) && (nSize <= 0xFFFF),
OStringBuffer("SfxOleStringHelper::ImplLoadString8 - invalid string of len "). OStringBuffer("SfxOleStringHelper::ImplLoadString8 - invalid string of len ").
append(nSize).getStr() ); append(nSize).getStr() );
if( (0 < nSize) && (nSize <= 0xFFFF) ) if (nSize > 0 && nSize <= 0xFFFF)
{ {
// load character buffer // load character buffer
::std::vector< sal_Char > aBuffer( static_cast< size_t >( nSize + 1 ), 0 ); OString sValue(read_uInt8s_ToOString(rStrm, nSize - 1));
rStrm.ReadBytes(aBuffer.data(), static_cast<std::size_t>(nSize)); rStrm.SeekRel(1); // skip null-byte at end
// create string from encoded character array aValue = OStringToOUString(sValue, GetTextEncoding());
aValue = OUString(aBuffer.data(), strlen(aBuffer.data()), GetTextEncoding());
} }
return aValue; return aValue;
} }
...@@ -292,23 +291,14 @@ OUString SfxOleStringHelper::ImplLoadString16( SvStream& rStrm ) ...@@ -292,23 +291,14 @@ OUString SfxOleStringHelper::ImplLoadString16( SvStream& rStrm )
rStrm.ReadInt32( nSize ); rStrm.ReadInt32( nSize );
DBG_ASSERT( (0 < nSize) && (nSize <= 0xFFFF), "SfxOleStringHelper::ImplLoadString16 - invalid string" ); DBG_ASSERT( (0 < nSize) && (nSize <= 0xFFFF), "SfxOleStringHelper::ImplLoadString16 - invalid string" );
// size field includes trailing NUL character // size field includes trailing NUL character
if( (0 < nSize) && (nSize <= 0xFFFF) ) if (nSize > 0 && nSize <= 0xFFFF)
{ {
// load character buffer // load character buffer
::std::vector< sal_Unicode > aBuffer; aValue = read_uInt16s_ToOUString(rStrm, nSize - 1);
aBuffer.reserve( static_cast< size_t >( nSize + 1 ) ); rStrm.SeekRel(2); // skip null-byte at end
sal_uInt16 cChar;
for( sal_Int32 nIdx = 0; nIdx < nSize; ++nIdx )
{
rStrm.ReadUInt16( cChar );
aBuffer.push_back( static_cast< sal_Unicode >( cChar ) );
}
// stream is always padded to 32-bit boundary, skip 2 bytes on odd character count // stream is always padded to 32-bit boundary, skip 2 bytes on odd character count
if( (nSize & 1) == 1 ) if( (nSize & 1) == 1 )
rStrm.SeekRel( 2 ); rStrm.SeekRel(2);
// create string from character array
aBuffer.push_back( 0 );
aValue = OUString(aBuffer.data());
} }
return aValue; return aValue;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment