tdf#67538 XTypeDetection::queryTypeByDescriptor poor performance, part2

SfxMedium was creating a temporary file and copying the input file, when
CloseInStream_Impl was called from the destructor. Very very bad for
performance.

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 16.1s to 9s.

Change-Id: If52f8e0587c7b11666893f6cb79b3180d45cce43
Reviewed-on: https://gerrit.libreoffice.org/73375
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
diff --git a/include/sfx2/docfile.hxx b/include/sfx2/docfile.hxx
index a8fae84..77950a4 100644
--- a/include/sfx2/docfile.hxx
+++ b/include/sfx2/docfile.hxx
@@ -60,9 +60,9 @@ class SFX2_DLLPUBLIC SfxMedium : public SvRefBase
    std::unique_ptr< SfxMedium_Impl > pImpl;

    SAL_DLLPRIVATE void SetIsRemote_Impl();
    SAL_DLLPRIVATE void CloseInStream_Impl();
    SAL_DLLPRIVATE void CloseInStream_Impl(bool bInDestruction = false);
    SAL_DLLPRIVATE void CloseOutStream_Impl();
    SAL_DLLPRIVATE void CloseStreams_Impl();
    SAL_DLLPRIVATE void CloseStreams_Impl(bool bInDestruction = false);

    SAL_DLLPRIVATE void SetEncryptionDataToStorage_Impl();

@@ -121,7 +121,7 @@ public:
    const OUString&     GetOrigURL() const;

    SfxItemSet  *       GetItemSet() const;
    void                Close();
    void                Close(bool bInDestruction = false);
    void                CloseAndRelease();
    void                ReOpen();
    void                CompleteReOpen();
diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx
index 1771044..265fd4e 100644
--- a/sfx2/source/doc/docfile.cxx
+++ b/sfx2/source/doc/docfile.cxx
@@ -593,7 +593,7 @@ void SfxMedium::CloseInStream()
    CloseInStream_Impl();
}

void SfxMedium::CloseInStream_Impl()
void SfxMedium::CloseInStream_Impl(bool bInDestruction)
{
    // if there is a storage based on the InStream, we have to
    // close the storage, too, because otherwise the storage
@@ -604,7 +604,7 @@ void SfxMedium::CloseInStream_Impl()
            CloseStorage();
    }

    if ( pImpl->m_pInStream && !GetContent().is() )
    if ( pImpl->m_pInStream && !GetContent().is() && !bInDestruction )
    {
        CreateTempFile();
        return;
@@ -2905,14 +2905,14 @@ sal_uInt32 SfxMedium::CreatePasswordToModifyHash( const OUString& aPasswd, bool 
}


void SfxMedium::Close()
void SfxMedium::Close(bool bInDestruction)
{
    if ( pImpl->xStorage.is() )
    {
        CloseStorage();
    }

    CloseStreams_Impl();
    CloseStreams_Impl(bInDestruction);

    UnlockFile( false );
}
@@ -3081,9 +3081,9 @@ void SfxMedium::CloseAndReleaseStreams_Impl()
}


void SfxMedium::CloseStreams_Impl()
void SfxMedium::CloseStreams_Impl(bool bInDestruction)
{
    CloseInStream_Impl();
    CloseInStream_Impl(bInDestruction);
    CloseOutStream_Impl();

    if ( pImpl->m_pSet )
@@ -3326,7 +3326,7 @@ SfxMedium::~SfxMedium()
    // if there is a requirement to clean the backup this is the last possibility to do it
    ClearBackup_Impl();

    Close();
    Close(/*bInDestruction*/true);

    if( !pImpl->bIsTemp || pImpl->m_aName.isEmpty() )
        return;