[Libreoffice-commits] core.git: ucb/source

Arkadiy Illarionov (via logerrit) logerrit at kemper.freedesktop.org
Sat Jun 29 18:11:16 UTC 2019


 ucb/source/ucp/file/filtask.cxx |  145 +++++++++++++++++++---------------------
 ucb/source/ucp/file/filtask.hxx |    3 
 2 files changed, 73 insertions(+), 75 deletions(-)

New commits:
commit 894880f40889b8f03dff8bb3d6f48b7a473d89b7
Author:     Arkadiy Illarionov <qarkai at gmail.com>
AuthorDate: Sat Jun 29 14:47:35 2019 +0300
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sat Jun 29 20:09:45 2019 +0200

    Flatten TaskManager::erasePersistentSet and TaskManager::copyPersistentSet
    
    Explicitly do operations without children
    
    Change-Id: Ice1d9562f6b40620c53c398bc6cc707e11be8f96
    Reviewed-on: https://gerrit.libreoffice.org/74876
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/ucb/source/ucp/file/filtask.cxx b/ucb/source/ucp/file/filtask.cxx
index 5a81536bdf38..656d84ca4e67 100644
--- a/ucb/source/ucp/file/filtask.cxx
+++ b/ucb/source/ucp/file/filtask.cxx
@@ -2788,6 +2788,26 @@ void TaskManager::notifyPropertyChanges(
 /********************************************************************************/
 
 void
+TaskManager::erasePersistentSetWithoutChildren( const OUString& aUnqPath )
+{
+    {
+        // Release possible references
+        osl::MutexGuard aGuard( m_aMutex );
+        ContentMap::iterator it = m_aContent.find( aUnqPath );
+        if( it != m_aContent.end() )
+        {
+            it->second.xS = nullptr;
+            it->second.xC = nullptr;
+            it->second.xA = nullptr;
+
+            it->second.properties.clear();
+        }
+    }
+
+    m_xFileRegistry->removePropertySet( aUnqPath );
+}
+
+void
 TaskManager::erasePersistentSet( const OUString& aUnqPath,
                            bool withChildren )
 {
@@ -2797,45 +2817,25 @@ TaskManager::erasePersistentSet( const OUString& aUnqPath,
         return;
     }
 
-    uno::Sequence< OUString > seqNames;
-
-    if( withChildren )
+    if( ! withChildren )
     {
-        uno::Reference< container::XNameAccess > xName( m_xFileRegistry,uno::UNO_QUERY );
-        seqNames = xName->getElementNames();
+        erasePersistentSetWithoutChildren(aUnqPath);
+        return;
     }
 
-    sal_Int32 count = withChildren ? seqNames.getLength() : 1;
+    uno::Reference< container::XNameAccess > xName( m_xFileRegistry,uno::UNO_QUERY );
+    uno::Sequence< OUString > seqNames = xName->getElementNames();
 
-    OUString
-        old_Name = aUnqPath;
+    OUString old_Name = aUnqPath;
 
-    for( sal_Int32 j = 0; j < count; ++j )
+    for( const auto& rName : seqNames )
     {
-        if( withChildren  && ! ( isChild( old_Name,seqNames[j] ) ) )
+        if( ! ( isChild( old_Name,rName ) ) )
             continue;
 
-        if( withChildren )
-        {
-            old_Name = seqNames[j];
-        }
-
-        {
-            // Release possible references
-            osl::MutexGuard aGuard( m_aMutex );
-            ContentMap::iterator it = m_aContent.find( old_Name );
-            if( it != m_aContent.end() )
-            {
-                it->second.xS = nullptr;
-                it->second.xC = nullptr;
-                it->second.xA = nullptr;
+        old_Name = rName;
 
-                it->second.properties.clear();
-            }
-        }
-
-        if( m_xFileRegistry.is() )
-            m_xFileRegistry->removePropertySet( old_Name );
+        erasePersistentSetWithoutChildren(old_Name);
     }
 }
 
@@ -2845,6 +2845,35 @@ TaskManager::erasePersistentSet( const OUString& aUnqPath,
 /*                       from srcUnqPath to dstUnqPath                          */
 /********************************************************************************/
 
+void
+TaskManager::copyPersistentSetWithoutChildren( const OUString& srcUnqPath,
+                          const OUString& dstUnqPath )
+{
+    uno::Reference< XPersistentPropertySet > x_src =
+            m_xFileRegistry->openPropertySet( srcUnqPath,false );
+    m_xFileRegistry->removePropertySet( dstUnqPath );
+
+    if( ! x_src.is() )
+        return;
+
+    uno::Sequence< beans::Property > seqProperty =
+        x_src->getPropertySetInfo()->getProperties();
+
+    if( ! seqProperty.hasElements() )
+        return;
+
+    uno::Reference< XPersistentPropertySet >
+        x_dstS = m_xFileRegistry->openPropertySet( dstUnqPath,true );
+    uno::Reference< beans::XPropertyContainer >
+        x_dstC( x_dstS,uno::UNO_QUERY );
+
+    for( const auto& rProperty : seqProperty )
+    {
+        x_dstC->addProperty( rProperty.Name,
+                             rProperty.Attributes,
+                             x_src->getPropertyValue( rProperty.Name ) );
+    }
+}
 
 void
 TaskManager::copyPersistentSet( const OUString& srcUnqPath,
@@ -2857,60 +2886,26 @@ TaskManager::copyPersistentSet( const OUString& srcUnqPath,
         return;
     }
 
-    uno::Sequence< OUString > seqNames;
-
-    if( withChildren )
+    if( ! withChildren )
     {
-        uno::Reference< container::XNameAccess > xName( m_xFileRegistry,uno::UNO_QUERY );
-        seqNames = xName->getElementNames();
+        copyPersistentSetWithoutChildren(srcUnqPath, dstUnqPath);
+        return;
     }
 
-    sal_Int32 count = withChildren ? seqNames.getLength() : 1;
+    uno::Reference< container::XNameAccess > xName( m_xFileRegistry,uno::UNO_QUERY );
+    uno::Sequence< OUString > seqNames = xName->getElementNames();
 
-    OUString
-        old_Name = srcUnqPath,
-        new_Name = dstUnqPath;
+    OUString new_Name;
 
-    for( sal_Int32 j = 0; j < count; ++j )
+    for( const auto& rName : seqNames )
     {
-        if( withChildren  && ! ( isChild( srcUnqPath,seqNames[j] ) ) )
+        if( ! ( isChild( srcUnqPath,rName ) ) )
             continue;
 
-        if( withChildren )
-        {
-            old_Name = seqNames[j];
-            new_Name = newName( dstUnqPath,srcUnqPath,old_Name );
-        }
-
-        uno::Reference< XPersistentPropertySet > x_src;
-
-        if( m_xFileRegistry.is() )
-        {
-            x_src = m_xFileRegistry->openPropertySet( old_Name,false );
-            m_xFileRegistry->removePropertySet( new_Name );
-        }
+        new_Name = newName( dstUnqPath,srcUnqPath,rName );
 
-        if( x_src.is() )
-        {
-            uno::Sequence< beans::Property > seqProperty =
-                x_src->getPropertySetInfo()->getProperties();
-
-            if( seqProperty.hasElements() )
-            {
-                uno::Reference< XPersistentPropertySet >
-                    x_dstS = m_xFileRegistry->openPropertySet( new_Name,true );
-                uno::Reference< beans::XPropertyContainer >
-                    x_dstC( x_dstS,uno::UNO_QUERY );
-
-                for( sal_Int32 i = 0; i < seqProperty.getLength(); ++i )
-                {
-                    x_dstC->addProperty( seqProperty[i].Name,
-                                         seqProperty[i].Attributes,
-                                         x_src->getPropertyValue( seqProperty[i].Name ) );
-                }
-            }
-        }
-    }         // end for( sal_Int...
+        copyPersistentSetWithoutChildren(rName, new_Name);
+    }
 }
 
 uno::Sequence< ucb::ContentInfo > TaskManager::queryCreatableContentsInfo()
diff --git a/ucb/source/ucp/file/filtask.hxx b/ucb/source/ucp/file/filtask.hxx
index 996aeba8865e..1bf1703bd1d5 100644
--- a/ucb/source/ucp/file/filtask.hxx
+++ b/ucb/source/ucp/file/filtask.hxx
@@ -557,6 +557,7 @@ namespace fileaccess
         /*                       remove persistent propertyset                          */
         /********************************************************************************/
 
+        void erasePersistentSetWithoutChildren( const OUString& aUnqPath );
         void erasePersistentSet( const OUString& aUnqPath,
                                           bool withChildren = false );
 
@@ -565,6 +566,8 @@ namespace fileaccess
         /*                       from srcUnqPath to dstUnqPath                          */
         /********************************************************************************/
 
+        void copyPersistentSetWithoutChildren( const OUString& srcUnqPath,
+                                const OUString& dstUnqPath );
         void copyPersistentSet( const OUString& srcUnqPath,
                                          const OUString& dstUnqPath,
                                          bool withChildren );


More information about the Libreoffice-commits mailing list