Kaydet (Commit) 1439a09a authored tarafından Noel Grandin's avatar Noel Grandin

tdf#67538 XTypeDetection::queryTypeByDescriptor poor performance, part1

Skip creating an intermediary buffer in XStream_impl::readBytes, and
just read directly into the destination.

This is specifically fixing the performance of queryTypeByDescriptor
when called from a basic macro on a local test file.

This takes my test macro from 17.1s to 16.1s.

Change-Id: Iaa7d38c6a90a3b3f01a4b748c4512dd8fda690c7
Reviewed-on: https://gerrit.libreoffice.org/73374
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 34bbf192
...@@ -130,10 +130,9 @@ XStream_impl::readBytes( ...@@ -130,10 +130,9 @@ XStream_impl::readBytes(
if( ! m_nIsOpen ) if( ! m_nIsOpen )
throw io::IOException( THROW_WHERE ); throw io::IOException( THROW_WHERE );
std::unique_ptr<sal_Int8[]> buffer;
try try
{ {
buffer.reset(new sal_Int8[nBytesToRead]); aData.realloc(nBytesToRead);
} }
catch (const std::bad_alloc&) catch (const std::bad_alloc&)
{ {
...@@ -142,12 +141,13 @@ XStream_impl::readBytes( ...@@ -142,12 +141,13 @@ XStream_impl::readBytes(
} }
sal_uInt64 nrc(0); sal_uInt64 nrc(0);
if(m_aFile.read( buffer.get(),sal_uInt64(nBytesToRead),nrc ) if(m_aFile.read( aData.getArray(), sal_uInt64(nBytesToRead), nrc )
!= osl::FileBase::E_None) != osl::FileBase::E_None)
{ {
throw io::IOException( THROW_WHERE ); throw io::IOException( THROW_WHERE );
} }
aData = uno::Sequence< sal_Int8 > ( buffer.get(), static_cast<sal_uInt32>(nrc) ); if (nrc != static_cast<sal_uInt64>(nBytesToRead))
aData.realloc(nrc);
return static_cast<sal_Int32>(nrc); return static_cast<sal_Int32>(nrc);
} }
......
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