From aed2107e1d003566d6cdb46c2bebe8b025d5f399 Mon Sep 17 00:00:00 2001 From: Julien Nabet Date: Fri, 2 Feb 2018 07:28:38 +0100 Subject: 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 Reviewed-by: Thorsten Behrens --- sdext/source/pdfimport/inc/pdfiprocessor.hxx | 2 +- sdext/source/pdfimport/tree/pdfiprocessor.cxx | 28 ++++----------------------- 2 files changed, 5 insertions(+), 25 deletions(-) (limited to 'sdext') 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 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 -- cgit v1.2.3