From 1439a09a13516f72baa735e5af332b0647d0cff7 Mon Sep 17 00:00:00 2001
From: Noel Grandin <noel.grandin@collabora.co.uk>
Date: Mon, 3 Jun 2019 10:00:58 +0200
Subject: 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: Noel Grandin <noel.grandin@collabora.co.uk>
---
 ucb/source/ucp/file/filstr.cxx | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

(limited to 'ucb/source/ucp')

diff --git a/ucb/source/ucp/file/filstr.cxx b/ucb/source/ucp/file/filstr.cxx
index a2419042de45..8b23813abdc4 100644
--- a/ucb/source/ucp/file/filstr.cxx
+++ b/ucb/source/ucp/file/filstr.cxx
@@ -130,10 +130,9 @@ XStream_impl::readBytes(
     if( ! m_nIsOpen )
         throw io::IOException( THROW_WHERE );
 
-    std::unique_ptr<sal_Int8[]> buffer;
     try
     {
-        buffer.reset(new sal_Int8[nBytesToRead]);
+        aData.realloc(nBytesToRead);
     }
     catch (const std::bad_alloc&)
     {
@@ -142,12 +141,13 @@ XStream_impl::readBytes(
     }
 
     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)
     {
         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);
 }
 
-- 
cgit