[Libreoffice-commits] core.git: comphelper/source include/comphelper svx/source sw/source

Noel Grandin noel at peralex.com
Tue Apr 5 06:26:47 UTC 2016


 comphelper/source/container/embeddedobjectcontainer.cxx |  116 +++++-----------
 comphelper/source/misc/SelectionMultiplex.cxx           |    9 -
 comphelper/source/streaming/seqstream.cxx               |   19 --
 comphelper/source/streaming/streamsection.cxx           |   25 ---
 include/comphelper/SelectionMultiplex.hxx               |    3 
 include/comphelper/embeddedobjectcontainer.hxx          |    4 
 include/comphelper/seqstream.hxx                        |    7 
 include/comphelper/streamsection.hxx                    |    6 
 svx/source/svdraw/svdoole2.cxx                          |    2 
 sw/source/core/ole/ndole.cxx                            |    4 
 10 files changed, 60 insertions(+), 135 deletions(-)

New commits:
commit b9372f0e909c32d143540bf0ce7b79003d9b26e9
Author: Noel Grandin <noel at peralex.com>
Date:   Mon Apr 4 15:01:55 2016 +0200

    loplugin:constantparam in comphelper
    
    Change-Id: I81e6af1ee869caa3b40d2d00604e8e22517d92d7
    Reviewed-on: https://gerrit.libreoffice.org/23808
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noelgrandin at gmail.com>

diff --git a/comphelper/source/container/embeddedobjectcontainer.cxx b/comphelper/source/container/embeddedobjectcontainer.cxx
index a37b2f0..6604be3 100644
--- a/comphelper/source/container/embeddedobjectcontainer.cxx
+++ b/comphelper/source/container/embeddedobjectcontainer.cxx
@@ -899,12 +899,11 @@ bool EmbeddedObjectContainer::MoveEmbeddedObject( EmbeddedObjectContainer& rSrc,
 }
 
 // #i119941, bKeepToTempStorage: use to specify whether store the removed object to temporary storage+
-bool EmbeddedObjectContainer::RemoveEmbeddedObject( const OUString& rName, bool bClose, bool bKeepToTempStorage )
+bool EmbeddedObjectContainer::RemoveEmbeddedObject( const OUString& rName, bool bKeepToTempStorage )
 {
     uno::Reference < embed::XEmbeddedObject > xObj = GetEmbeddedObject( rName );
     if ( xObj.is() )
-        //return RemoveEmbeddedObject( xObj, bClose );
-        return RemoveEmbeddedObject( xObj, bClose, bKeepToTempStorage );
+        return RemoveEmbeddedObject( xObj, bKeepToTempStorage );
     else
         return false;
 }
@@ -960,9 +959,8 @@ bool EmbeddedObjectContainer::MoveEmbeddedObject( const OUString& rName, Embedde
     return false;
 }
 
-//sal_Bool EmbeddedObjectContainer::RemoveEmbeddedObject( const uno::Reference < embed::XEmbeddedObject >& xObj, sal_Bool bClose )
 // #i119941, bKeepToTempStorage: use to specify whether store the removed object to temporary storage+
-bool EmbeddedObjectContainer::RemoveEmbeddedObject( const uno::Reference < embed::XEmbeddedObject >& xObj, bool bClose, bool bKeepToTempStorage )
+bool EmbeddedObjectContainer::RemoveEmbeddedObject( const uno::Reference < embed::XEmbeddedObject >& xObj, bool bKeepToTempStorage )
 {
     uno::Reference < embed::XEmbedPersist > xPersist( xObj, uno::UNO_QUERY );
     OUString aName;
@@ -978,86 +976,54 @@ bool EmbeddedObjectContainer::RemoveEmbeddedObject( const uno::Reference < embed
     OSL_ENSURE( bIsNotEmbedded || xAccess->hasByName(aName), "Removing element not present in storage!" );
 #endif
 
-    // try to close it if permitted
-    if ( bClose )
+    // somebody still needs the object, so we must assign a temporary persistence
+    try
     {
-        uno::Reference < ::util::XCloseable > xClose( xObj, uno::UNO_QUERY );
-        try
-        {
-            xClose->close( sal_True );
-        }
-        catch (const util::CloseVetoException&)
+        if ( xPersist.is() && bKeepToTempStorage ) // #i119941
         {
-            bClose = false;
-        }
-    }
 
-    if ( !bClose )
-    {
-        // somebody still needs the object, so we must assign a temporary persistence
-        try
-        {
-        //    if ( xPersist.is() )
-             if ( xPersist.is() && bKeepToTempStorage ) // #i119941
+            if ( !pImpl->mpTempObjectContainer )
             {
-                /*
-                //TODO/LATER: needs storage handling!  Why not letting the object do it?!
-                if ( !pImpl->mxTempStorage.is() )
-                    pImpl->mxTempStorage = ::comphelper::OStorageHelper::GetTemporaryStorage();
-                uno::Sequence < beans::PropertyValue > aSeq;
-
-                OUString aTmpPersistName = "Object ";
-                aTmpPersistName += OUString::valueOf( (sal_Int32) pImpl->maTempObjectContainer.size() );
-
-                xPersist->storeAsEntry( pImpl->mxTempStorage, aTmpPersistName, aSeq, aSeq );
-                xPersist->saveCompleted( sal_True );
-
-                pImpl->maTempObjectContainer[ aTmpPersistName ].clear();
-                */
-
-                if ( !pImpl->mpTempObjectContainer )
+                pImpl->mpTempObjectContainer = new EmbeddedObjectContainer();
+                try
                 {
-                    pImpl->mpTempObjectContainer = new EmbeddedObjectContainer();
-                    try
-                    {
-                        // TODO/LATER: in future probably the temporary container will have two storages ( of two formats )
-                        //             the media type will be provided with object insertion
-                        OUString aOrigStorMediaType;
-                        uno::Reference< beans::XPropertySet > xStorProps( pImpl->mxStorage, uno::UNO_QUERY_THROW );
-                        static const OUString s_sMediaType("MediaType");
-                        xStorProps->getPropertyValue( s_sMediaType ) >>= aOrigStorMediaType;
-
-                        SAL_WARN_IF( aOrigStorMediaType.isEmpty(), "comphelper.container", "No valuable media type in the storage!\n" );
-
-                        uno::Reference< beans::XPropertySet > xTargetStorProps(
-                                                                    pImpl->mpTempObjectContainer->pImpl->mxStorage,
-                                                                    uno::UNO_QUERY_THROW );
-                        xTargetStorProps->setPropertyValue( s_sMediaType,uno::makeAny( aOrigStorMediaType ) );
-                    }
-                    catch (const uno::Exception&)
-                    {
-                        SAL_WARN( "comphelper.container", "Can not set the new media type to a storage!\n" );
-                    }
+                    // TODO/LATER: in future probably the temporary container will have two storages ( of two formats )
+                    //             the media type will be provided with object insertion
+                    OUString aOrigStorMediaType;
+                    uno::Reference< beans::XPropertySet > xStorProps( pImpl->mxStorage, uno::UNO_QUERY_THROW );
+                    static const OUString s_sMediaType("MediaType");
+                    xStorProps->getPropertyValue( s_sMediaType ) >>= aOrigStorMediaType;
+
+                    SAL_WARN_IF( aOrigStorMediaType.isEmpty(), "comphelper.container", "No valuable media type in the storage!\n" );
+
+                    uno::Reference< beans::XPropertySet > xTargetStorProps(
+                                                                pImpl->mpTempObjectContainer->pImpl->mxStorage,
+                                                                uno::UNO_QUERY_THROW );
+                    xTargetStorProps->setPropertyValue( s_sMediaType,uno::makeAny( aOrigStorMediaType ) );
+                }
+                catch (const uno::Exception&)
+                {
+                    SAL_WARN( "comphelper.container", "Can not set the new media type to a storage!\n" );
                 }
+            }
 
-                OUString aTempName, aMediaType;
-                pImpl->mpTempObjectContainer->InsertEmbeddedObject( xObj, aTempName );
+            OUString aTempName, aMediaType;
+            pImpl->mpTempObjectContainer->InsertEmbeddedObject( xObj, aTempName );
 
-                uno::Reference < io::XInputStream > xStream = GetGraphicStream( xObj, &aMediaType );
-                if ( xStream.is() )
-                    pImpl->mpTempObjectContainer->InsertGraphicStream( xStream, aTempName, aMediaType );
+            uno::Reference < io::XInputStream > xStream = GetGraphicStream( xObj, &aMediaType );
+            if ( xStream.is() )
+                pImpl->mpTempObjectContainer->InsertGraphicStream( xStream, aTempName, aMediaType );
 
-                // object is stored, so at least it can be set to loaded state
-                xObj->changeState( embed::EmbedStates::LOADED );
-            }
-            else
-                // objects without persistence need to stay in running state if they shall not be closed
-                xObj->changeState( embed::EmbedStates::RUNNING );
-        }
-        catch (const uno::Exception&)
-        {
-            return false;
+            // object is stored, so at least it can be set to loaded state
+            xObj->changeState( embed::EmbedStates::LOADED );
         }
+        else
+            // objects without persistence need to stay in running state if they shall not be closed
+            xObj->changeState( embed::EmbedStates::RUNNING );
+    }
+    catch (const uno::Exception&)
+    {
+        return false;
     }
 
     bool bFound = false;
diff --git a/comphelper/source/misc/SelectionMultiplex.cxx b/comphelper/source/misc/SelectionMultiplex.cxx
index 26a191c..9f853ed 100644
--- a/comphelper/source/misc/SelectionMultiplex.cxx
+++ b/comphelper/source/misc/SelectionMultiplex.cxx
@@ -61,12 +61,11 @@ void OSelectionChangeListener::setAdapter(OSelectionChangeMultiplexer* pAdapter)
     }
 }
 
-OSelectionChangeMultiplexer::OSelectionChangeMultiplexer(OSelectionChangeListener* _pListener, const  Reference< XSelectionSupplier>& _rxSet, bool _bAutoReleaseSet)
+OSelectionChangeMultiplexer::OSelectionChangeMultiplexer(OSelectionChangeListener* _pListener, const  Reference< XSelectionSupplier>& _rxSet)
             :m_xSet(_rxSet)
             ,m_pListener(_pListener)
             ,m_nLockCount(0)
             ,m_bListening(false)
-            ,m_bAutoSetRelease(_bAutoReleaseSet)
 {
     m_pListener->setAdapter(this);
     osl_atomic_increment(&m_refCount);
@@ -108,8 +107,7 @@ void OSelectionChangeMultiplexer::dispose()
         m_pListener = nullptr;
         m_bListening = false;
 
-        if (m_bAutoSetRelease)
-            m_xSet = nullptr;
+        m_xSet = nullptr;
     }
 }
 
@@ -130,8 +128,7 @@ void SAL_CALL OSelectionChangeMultiplexer::disposing( const  EventObject& _rSour
     m_pListener = nullptr;
     m_bListening = false;
 
-    if (m_bAutoSetRelease)
-        m_xSet = nullptr;
+    m_xSet = nullptr;
 }
 
 // XSelectionChangeListener
diff --git a/comphelper/source/streaming/seqstream.cxx b/comphelper/source/streaming/seqstream.cxx
index 2cc98da..d4672f6 100644
--- a/comphelper/source/streaming/seqstream.cxx
+++ b/comphelper/source/streaming/seqstream.cxx
@@ -138,23 +138,17 @@ sal_Int64 SAL_CALL SequenceInputStream::getLength(  ) throw (IOException, Runtim
 }
 
 
-OSequenceOutputStream::OSequenceOutputStream(Sequence< sal_Int8 >& _rSeq, double _nResizeFactor, sal_Int32 _nMinimumResize, sal_Int32 _nMaximumResize)
+OSequenceOutputStream::OSequenceOutputStream(Sequence< sal_Int8 >& _rSeq, double _nResizeFactor, sal_Int32 _nMinimumResize)
     :m_rSequence(_rSeq)
     ,m_nResizeFactor(_nResizeFactor)
     ,m_nMinimumResize(_nMinimumResize)
-    ,m_nMaximumResize(_nMaximumResize)
     ,m_nSize(0) // starting at position 0
     ,m_bConnected(true)
 {
     OSL_ENSURE(m_nResizeFactor > 1, "OSequenceOutputStream::OSequenceOutputStream : invalid resize factor !");
-    OSL_ENSURE((m_nMaximumResize < 0) || (m_nMaximumResize > m_nMinimumResize),
-        "OSequenceOutputStream::OSequenceOutputStream : these limits don't make any sense !");
 
     if (m_nResizeFactor <= 1)
         m_nResizeFactor = 1.3;
-    if ((m_nMaximumResize >= 0) && (m_nMaximumResize <= m_nMinimumResize))
-        m_nMaximumResize = m_nMinimumResize * 2;
-        // this heuristic is as good as any other ... supply better parameters if you don't like it :)
 }
 
 
@@ -175,23 +169,12 @@ void SAL_CALL OSequenceOutputStream::writeBytes( const Sequence< sal_Int8 >& _rD
             // we have a minimum so it's not too inefficient for small sequences and small write requests
             nNewLength = nCurrentLength + m_nMinimumResize;
 
-        if ((m_nMaximumResize > 0) && (nNewLength - nCurrentLength > m_nMaximumResize))
-            // such a large step is not allowed
-            nNewLength = nCurrentLength + m_nMaximumResize;
-
         if (nNewLength < m_nSize + _rData.getLength())
         {   // it's not enough .... the data would not fit
 
             // let's take the double amount of the length of the data to be written, as the next write
             // request could be as large as this one
             sal_Int32 nNewGrowth = _rData.getLength() * 2;
-            if ((m_nMaximumResize > 0) && (nNewGrowth > m_nMaximumResize))
-            {   // we came to the limit, again ...
-                nNewGrowth = m_nMaximumResize;
-                if (nNewGrowth + nCurrentLength < m_nSize + _rData.getLength())
-                    // but it would not fit if we respect the limit
-                    nNewGrowth = m_nSize + _rData.getLength() - nCurrentLength;
-            }
             nNewLength = nCurrentLength + nNewGrowth;
         }
 
diff --git a/comphelper/source/streaming/streamsection.cxx b/comphelper/source/streaming/streamsection.cxx
index 4ff71da..f6165c7 100644
--- a/comphelper/source/streaming/streamsection.cxx
+++ b/comphelper/source/streaming/streamsection.cxx
@@ -39,7 +39,7 @@ OStreamSection::OStreamSection(const css::uno::Reference< css::io::XDataInputStr
 }
 
 
-OStreamSection::OStreamSection(const css::uno::Reference< css::io::XDataOutputStream >& _rxOutput, sal_Int32 _nPresumedLength)
+OStreamSection::OStreamSection(const css::uno::Reference< css::io::XDataOutputStream >& _rxOutput)
     :m_xMarkStream(_rxOutput, css::uno::UNO_QUERY)
     ,m_xOutStream(_rxOutput)
     ,m_nBlockStart(-1)
@@ -49,12 +49,7 @@ OStreamSection::OStreamSection(const css::uno::Reference< css::io::XDataOutputSt
     if (m_xOutStream.is() && m_xMarkStream.is())
     {
         m_nBlockStart = m_xMarkStream->createMark();
-        // a placeholder where we will write the overall length (within the destructor)
-        if (_nPresumedLength > 0)
-            m_nBlockLen = _nPresumedLength + sizeof(m_nBlockLen);
-            // as the caller did not consider - of course - the placeholder we are going to write
-        else
-            m_nBlockLen = 0;
+        m_nBlockLen = 0;
         m_xOutStream->writeLong(m_nBlockLen);
     }
 }
@@ -74,17 +69,11 @@ OStreamSection::~OStreamSection()
         else if (m_xOutStream.is() && m_xMarkStream.is())
         {
             sal_Int32 nRealBlockLength = m_xMarkStream->offsetToMark(m_nBlockStart) - sizeof(m_nBlockLen);
-            if (m_nBlockLen && (m_nBlockLen == nRealBlockLength))
-                // nothing to do : the estimation the caller gave us (in the ctor) was correct
-                m_xMarkStream->deleteMark(m_nBlockStart);
-            else
-            {   // the estimation was wrong (or we didn't get one)
-                m_nBlockLen = nRealBlockLength;
-                m_xMarkStream->jumpToMark(m_nBlockStart);
-                m_xOutStream->writeLong(m_nBlockLen);
-                m_xMarkStream->jumpToFurthest();
-                m_xMarkStream->deleteMark(m_nBlockStart);
-            }
+            m_nBlockLen = nRealBlockLength;
+            m_xMarkStream->jumpToMark(m_nBlockStart);
+            m_xOutStream->writeLong(m_nBlockLen);
+            m_xMarkStream->jumpToFurthest();
+            m_xMarkStream->deleteMark(m_nBlockStart);
         }
     }
     catch(const css::uno::Exception&)
diff --git a/include/comphelper/SelectionMultiplex.hxx b/include/comphelper/SelectionMultiplex.hxx
index 3755f36..fa92e3c 100644
--- a/include/comphelper/SelectionMultiplex.hxx
+++ b/include/comphelper/SelectionMultiplex.hxx
@@ -71,14 +71,13 @@ namespace comphelper
         OSelectionChangeListener*                            m_pListener;
         sal_Int32                                            m_nLockCount;
         bool                                                 m_bListening        : 1;
-        bool                                                 m_bAutoSetRelease   : 1;
 
         OSelectionChangeMultiplexer(const OSelectionChangeMultiplexer&) = delete;
         OSelectionChangeMultiplexer& operator=(const OSelectionChangeMultiplexer&) = delete;
     protected:
         virtual ~OSelectionChangeMultiplexer();
     public:
-        OSelectionChangeMultiplexer(OSelectionChangeListener* _pListener, const  css::uno::Reference< css::view::XSelectionSupplier>& _rxSet, bool _bAutoReleaseSet = true);
+        OSelectionChangeMultiplexer(OSelectionChangeListener* _pListener, const  css::uno::Reference< css::view::XSelectionSupplier>& _rxSet);
 
     // XEventListener
         virtual void SAL_CALL disposing( const  css::lang::EventObject& Source ) throw( css::uno::RuntimeException, std::exception) override;
diff --git a/include/comphelper/embeddedobjectcontainer.hxx b/include/comphelper/embeddedobjectcontainer.hxx
index 2e73050..27992e1 100644
--- a/include/comphelper/embeddedobjectcontainer.hxx
+++ b/include/comphelper/embeddedobjectcontainer.hxx
@@ -134,8 +134,8 @@ public:
 
     // remove an embedded object from the container and from the storage; if object can't be closed
     // #i119941, bKeepToTempStorage: use to specify whether store the removed object to temporary storage+
-    bool            RemoveEmbeddedObject( const OUString& rName, bool bClose = true, bool bKeepToTempStorage = true );
-    bool            RemoveEmbeddedObject( const css::uno::Reference < css::embed::XEmbeddedObject >&, bool bClose = true, bool bKeepToTempStorage = true );
+    bool            RemoveEmbeddedObject( const OUString& rName, bool bKeepToTempStorage = true);
+    bool            RemoveEmbeddedObject( const css::uno::Reference < css::embed::XEmbeddedObject >&, bool bKeepToTempStorage = true);
 
     // close and remove an embedded object from the container without removing it from the storage
     bool            CloseEmbeddedObject( const css::uno::Reference < css::embed::XEmbeddedObject >& );
diff --git a/include/comphelper/seqstream.hxx b/include/comphelper/seqstream.hxx
index 79d6448..49e4911 100644
--- a/include/comphelper/seqstream.hxx
+++ b/include/comphelper/seqstream.hxx
@@ -83,7 +83,6 @@ protected:
     css::uno::Sequence< sal_Int8 >&                 m_rSequence;
     double                                          m_nResizeFactor;
     sal_Int32                                       m_nMinimumResize;
-    sal_Int32                                       m_nMaximumResize;
     sal_Int32                                       m_nSize;
         // the size of the virtual stream. This is not the size of the sequence, but the number of bytes written
         // into the stream at a given moment.
@@ -107,16 +106,12 @@ public:
                                         resize step, the new sequence size will be calculated by multiplying the current
                                         size with this factor, rounded off to the next multiple of 4.
         @param      _nMinimumResize     the minmal number of bytes which is additionally allocated on resizing
-        @param      _nMaximumResize     as the growth of the stream size is exponential, you may want to specify a
-                                        maxmimum amount of memory which the sequence will grow by. If -1 is used,
-                                        no limit is applied
         @see        closeOutput
     */
     OSequenceOutputStream(
         css::uno::Sequence< sal_Int8 >& _rSeq,
         double _nResizeFactor = 1.3,
-        sal_Int32 _nMinimumResize = 128,
-        sal_Int32 _nMaximumResize = -1
+        sal_Int32 _nMinimumResize = 128
         );
 
     /// same as XOutputStream::writeBytes (as expected :)
diff --git a/include/comphelper/streamsection.hxx b/include/comphelper/streamsection.hxx
index 7a405d5..4a53c85 100644
--- a/include/comphelper/streamsection.hxx
+++ b/include/comphelper/streamsection.hxx
@@ -55,12 +55,8 @@ public:
     /** starts writing of a "skippable" section of data into the given output stream
         @param      _rxOutput           the stream the stream to write to. Must support the
                                         css::io::XMarkableStream interface
-        @param      _nPresumedLength    estimation for the length of the upcoming section. If greater 0, this
-                                        value will be written as section length and corrected (in the dtor) only if
-                                        needed. If you know how much bytes you are about to write, you may
-                                        want to use this param, saving some stream operations this way.
     */
-    OStreamSection(const css::uno::Reference< css::io::XDataOutputStream >& _rxOutput, sal_Int32 _nPresumedLength = 0);
+    OStreamSection(const css::uno::Reference< css::io::XDataOutputStream >& _rxOutput);
 
     /** dtor. <BR>If constructed for writing, the section "opened" by this object will be "closed".<BR>
         If constructed for reading, any remaining bytes 'til the end of the section will be skipped.
diff --git a/svx/source/svdraw/svdoole2.cxx b/svx/source/svdraw/svdoole2.cxx
index 7bf0ffe..bfcd7d5 100644
--- a/svx/source/svdraw/svdoole2.cxx
+++ b/svx/source/svdraw/svdoole2.cxx
@@ -1262,7 +1262,7 @@ void SdrOle2Obj::Disconnect_Impl()
                     comphelper::EmbeddedObjectContainer* pContainer = mpImpl->mxObjRef.GetContainer();
                     if ( pContainer )
                     {
-                        pContainer->RemoveEmbeddedObject( mpImpl->mxObjRef.GetObject(), false);
+                        pContainer->RemoveEmbeddedObject( mpImpl->mxObjRef.GetObject() );
 
                         // TODO/LATER: mpImpl->aPersistName contains outdated information, to keep it updated
                         // it should be returned from RemoveEmbeddedObject call. Currently it is no problem,
diff --git a/sw/source/core/ole/ndole.cxx b/sw/source/core/ole/ndole.cxx
index 7358a69..83ca269 100644
--- a/sw/source/core/ole/ndole.cxx
+++ b/sw/source/core/ole/ndole.cxx
@@ -347,7 +347,7 @@ bool SwOLENode::SavePersistentData()
                 }
             }
 
-            pCnt->RemoveEmbeddedObject( aOLEObj.aName, false, bKeepObjectToTempStorage );
+            pCnt->RemoveEmbeddedObject( aOLEObj.aName, bKeepObjectToTempStorage );
 
             // TODO/LATER: aOLEObj.aName has no meaning here, since the undo container contains the object
             // by different name, in future it might makes sense that the name is transported here.
@@ -701,7 +701,7 @@ SwOLEObj::~SwOLEObj()
             try
             {
                 // remove object from container but don't close it
-                pCnt->RemoveEmbeddedObject( aName, false);
+                pCnt->RemoveEmbeddedObject( aName );
             }
             catch ( uno::Exception& )
             {


More information about the Libreoffice-commits mailing list