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

Julien Nabet serval2412 at yahoo.fr
Fri Feb 2 18:50:13 UTC 2018


 sdext/source/pdfimport/inc/pdfiprocessor.hxx  |    2 -
 sdext/source/pdfimport/tree/pdfiprocessor.cxx |   28 +++-----------------------
 2 files changed, 5 insertions(+), 25 deletions(-)

New commits:
commit aed2107e1d003566d6cdb46c2bebe8b025d5f399
Author: Julien Nabet <serval2412 at yahoo.fr>
Date:   Fri Feb 2 07:28:38 2018 +0100

    Simplify sortElements in pdfiprocessor (sdext)
    
    For explanation, see:
    http://nabble.documentfoundation.org/About-simplifying-sortElements-in-pdfiprocessor-sdext-tt4231909.html
    
    Change-Id: I53fb732d776d7152279e5fc1440eafac1cfd71fe
    Reviewed-on: https://gerrit.libreoffice.org/49127
    Tested-by: Julien Nabet <serval2412 at yahoo.fr>
    Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>

diff --git a/sdext/source/pdfimport/inc/pdfiprocessor.hxx b/sdext/source/pdfimport/inc/pdfiprocessor.hxx
index f0662b8b1ad9..952944e3dc74 100644
--- a/sdext/source/pdfimport/inc/pdfiprocessor.hxx
+++ b/sdext/source/pdfimport/inc/pdfiprocessor.hxx
@@ -90,7 +90,7 @@ namespace pdfi
         const FontAttributes& getFont( sal_Int32 nFontId ) const;
         sal_Int32 getFontId( const FontAttributes& rAttr ) const;
 
-        void sortElements( Element* pElement, bool bDeep = false );
+        void sortElements( Element* pElement );
 
         static OUString mirrorString( const OUString& i_rInString );
 
diff --git a/sdext/source/pdfimport/tree/pdfiprocessor.cxx b/sdext/source/pdfimport/tree/pdfiprocessor.cxx
index 4937e332d6f6..6599d7430b4c 100644
--- a/sdext/source/pdfimport/tree/pdfiprocessor.cxx
+++ b/sdext/source/pdfimport/tree/pdfiprocessor.cxx
@@ -685,34 +685,14 @@ static bool lr_tb_sort( Element* pLeft, Element* pRight )
     return false;
 }
 
-void PDFIProcessor::sortElements( Element* pEle, bool bDeep )
+void PDFIProcessor::sortElements(Element* pEle)
 {
     if( pEle->Children.empty() )
         return;
 
-    if( bDeep )
-    {
-        for (auto const& child : pEle->Children)
-        {
-            sortElements( child, bDeep );
-        }
-    }
-    // HACK: the stable sort member on std::list that takes a
-    // strict weak ordering requires member templates - which we
-    // do not have on all compilers. so we need to use std::stable_sort
-    // here - which does need random access iterators which the
-    // list iterators are not.
-    // so we need to copy the Element* to an array, stable sort that and
-    // copy them back.
-    std::vector<Element*> aChildren;
-    while( ! pEle->Children.empty() )
-    {
-        aChildren.push_back( pEle->Children.front() );
-        pEle->Children.pop_front();
-    }
-    std::stable_sort( aChildren.begin(), aChildren.end(), lr_tb_sort );
-    for (auto const& child : aChildren)
-        pEle->Children.push_back(child);
+    // sort method from std::list is equivalent to stable_sort
+    // See S Meyers, Effective STL
+    pEle->Children.sort(lr_tb_sort);
 }
 
 // helper method: get a mirrored string


More information about the Libreoffice-commits mailing list