[Libreoffice-commits] core.git: Branch 'feature/profilesafemode' - comphelper/source configmgr/source

Armin Le Grand Armin.Le.Grand at cib.de
Wed Sep 28 09:43:29 UTC 2016


 comphelper/source/misc/backupfilehelper.cxx |   25 ++++++++++++++++++-------
 configmgr/source/writemodfile.cxx           |   22 ++++++++++++----------
 2 files changed, 30 insertions(+), 17 deletions(-)

New commits:
commit 17b319967e3ee94ffb4fb57bb6b810f42dd669b8
Author: Armin Le Grand <Armin.Le.Grand at cib.de>
Date:   Wed Sep 28 11:38:27 2016 +0200

    profilesafe: diverse adaptions
    
    Use Vector for better mem performance for sorting,
    defined static const for buffer size of manipulation,
    prepare inflate/deflate usages
    
    Change-Id: I864a6c2505dcf5e2c8ee265a5c04af01b65c3af4

diff --git a/comphelper/source/misc/backupfilehelper.cxx b/comphelper/source/misc/backupfilehelper.cxx
index 628ec2b..b679431 100644
--- a/comphelper/source/misc/backupfilehelper.cxx
+++ b/comphelper/source/misc/backupfilehelper.cxx
@@ -16,6 +16,7 @@
 #include <deque>
 
 typedef std::shared_ptr< osl::File > FileSharedPtr;
+static const sal_uInt32 BACKUP_FILE_HELPER_BLOCK_SIZE = 1024;
 
 namespace
 {
@@ -47,7 +48,7 @@ namespace
 
         if (rCandidate && osl::File::E_None == rCandidate->open(osl_File_OpenFlag_Read))
         {
-            sal_uInt8 aArray[1024];
+            sal_uInt8 aArray[BACKUP_FILE_HELPER_BLOCK_SIZE];
             sal_uInt64 nBytesTransfer(0);
             sal_uInt64 nSize(0);
 
@@ -60,7 +61,7 @@ namespace
 
             while (nSize != 0)
             {
-                const sal_uInt64 nToTransfer(std::min(nSize, (sal_uInt64)1024));
+                const sal_uInt64 nToTransfer(std::min(nSize, (sal_uInt64)BACKUP_FILE_HELPER_BLOCK_SIZE));
 
                 if (osl::File::E_None == rCandidate->read(static_cast<void*>(aArray), nToTransfer, nBytesTransfer) && nBytesTransfer == nToTransfer)
                 {
@@ -192,20 +193,30 @@ namespace
             return true;
         }
 
-        bool copy_content(oslFileHandle& rTargetHandle)
+        bool copy_content(oslFileHandle& rTargetHandle, bool bInflate)
         {
             if (maFile && osl::File::E_None == maFile->open(osl_File_OpenFlag_Read))
             {
-                sal_uInt8 aArray[1024];
+                sal_uInt8 aArray[BACKUP_FILE_HELPER_BLOCK_SIZE];
                 sal_uInt64 nBytesTransfer(0);
                 sal_uInt64 nSize(getSize());
 
                 // set offset in source file - when this is zero, a new file is to be added
+                const bool bNewFile(0 == getOffset());
                 maFile->setPos(0, sal_Int64(getOffset()));
 
+                if (!bInflate)
+                {
+                    // copy-back, deflate file
+                }
+                else if (bNewFile)
+                {
+                    // new file gets added, inflate initially
+                }
+
                 while (nSize != 0)
                 {
-                    const sal_uInt64 nToTransfer(std::min(nSize, (sal_uInt64)1024));
+                    const sal_uInt64 nToTransfer(std::min(nSize, (sal_uInt64)BACKUP_FILE_HELPER_BLOCK_SIZE));
 
                     if (osl::File::E_None != maFile->read(static_cast<void*>(aArray), nToTransfer, nBytesTransfer) || nBytesTransfer != nToTransfer)
                     {
@@ -376,7 +387,7 @@ namespace
                                 // write contents
                                 for (auto& candidateB : maPackedFileEntryVector)
                                 {
-                                    if (!candidateB.copy_content(aHandle))
+                                    if (!candidateB.copy_content(aHandle, true))
                                     {
                                         bRetval = false;
                                         break;
@@ -484,7 +495,7 @@ namespace
                 // already backups there, check if different from last entry
                 PackedFileEntry& aLastEntry = maPackedFileEntryVector.back();
 
-                bRetval = aLastEntry.copy_content(rHandle);
+                bRetval = aLastEntry.copy_content(rHandle, false);
 
                 if (bRetval)
                 {
diff --git a/configmgr/source/writemodfile.cxx b/configmgr/source/writemodfile.cxx
index 15c9ffa..381ab00 100644
--- a/configmgr/source/writemodfile.cxx
+++ b/configmgr/source/writemodfile.cxx
@@ -401,10 +401,10 @@ void writeNode(
 }
 
 // helpers to allow sorting of configmgr::Modifications::Node
-typedef std::pair< const rtl::OUString, configmgr::Modifications::Node > aPairEntry;
+typedef std::pair< const rtl::OUString, configmgr::Modifications::Node > ModNodePairEntry;
 struct PairEntrySorter
 {
-    bool operator() (const aPairEntry* pValue1, const aPairEntry* pValue2) const
+    bool operator() (const ModNodePairEntry* pValue1, const ModNodePairEntry* pValue2) const
     {
         return pValue1->first.compareTo(pValue2->first) < 0;
     }
@@ -472,19 +472,20 @@ void writeModifications(
 
         // copy configmgr::Modifications::Node's to a sortable list. Use pointers
         // to just reference the data instead of copying it
-        std::list< const aPairEntry* > aPairEntryList;
+        std::vector< const ModNodePairEntry* > ModNodePairEntryVector;
+        ModNodePairEntryVector.reserve(modifications.children.size());
 
         for (const auto& rCand : modifications.children)
         {
-            aPairEntryList.push_back(&rCand);
+            ModNodePairEntryVector.push_back(&rCand);
         }
 
         // sort the list
-        aPairEntryList.sort(PairEntrySorter());
+        std::sort(ModNodePairEntryVector.begin(), ModNodePairEntryVector.end(), PairEntrySorter());
 
         // now use the list to write entries in sorted order
         // instead of random as from the unordered map
-        for (const auto & i : aPairEntryList)
+        for (const auto & i : ModNodePairEntryVector)
         {
             writeModifications(
                 components, handle, pathRep, node, i->first,
@@ -637,19 +638,20 @@ void writeModFile(
 
     // copy configmgr::Modifications::Node's to a sortable list. Use pointers
     // to just reference the data instead of copying it
-    std::list< const aPairEntry* > aPairEntryList;
+    std::vector< const ModNodePairEntry* > ModNodePairEntryVector;
+    ModNodePairEntryVector.reserve(data.modifications.getRoot().children.size());
 
     for (const auto& rCand : data.modifications.getRoot().children)
     {
-        aPairEntryList.push_back(&rCand);
+        ModNodePairEntryVector.push_back(&rCand);
     }
 
     // sort the list
-    aPairEntryList.sort(PairEntrySorter());
+    std::sort(ModNodePairEntryVector.begin(), ModNodePairEntryVector.end(), PairEntrySorter());
 
     // now use the list to write entries in sorted order
     // instead of random as from the unordered map
-    for (const auto& j : aPairEntryList)
+    for (const auto& j : ModNodePairEntryVector)
     {
         writeModifications(
             components, tmp, "", rtl::Reference< Node >(), j->first,


More information about the Libreoffice-commits mailing list