diff options
author | Katarina Behrens <Katarina.Behrens@cib.de> | 2019-07-01 18:20:02 +0200 |
---|---|---|
committer | Katarina Behrens <Katarina.Behrens@cib.de> | 2019-10-25 16:27:04 +0200 |
commit | a8b1699ca9c7e8c43eff79467451fd1fcb4fde9b (patch) | |
tree | 685f005a1b6c417c3b582d80dce51d0138970cff /xmloff | |
parent | edcc3d66f9a107b8d9ffb3c5899e7863cf508484 (diff) |
speed-up shape import if shapes need z-order rearranging
setting z-order individually on each shape and broadcasting is
O(n^2) (remaining shapes also need reordering) and this is bad
bad bad for performance
Change-Id: Ic9c9137a097f6ff524192693910f221885f77cc4
Reviewed-on: https://gerrit.libreoffice.org/75055
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@cib.de>
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/source/draw/shapeimport.cxx | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/xmloff/source/draw/shapeimport.cxx b/xmloff/source/draw/shapeimport.cxx index f3a5183b976e..6708e48e73dc 100644 --- a/xmloff/source/draw/shapeimport.cxx +++ b/xmloff/source/draw/shapeimport.cxx @@ -23,6 +23,7 @@ #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/text/PositionLayoutDir.hpp> +#include <com/sun/star/drawing/XShapes3.hpp> #include <utility> #include <xmloff/unointerfacetouniqueidentifiermapper.hxx> @@ -795,9 +796,45 @@ void ShapeSortContext::popGroupAndSort() while( nCount ); } + bool bSorted = std::is_sorted(maZOrderList.begin(), maZOrderList.end(), + [&](const ZOrderHint& rLeft, const ZOrderHint& rRight) + { return rLeft.nShould < rRight.nShould; } ); + + if (bSorted) + return; // nothin' to do + // sort z-ordered shapes by nShould field std::sort(maZOrderList.begin(), maZOrderList.end()); + uno::Reference<drawing::XShapes3> xShapes3(mxShapes, uno::UNO_QUERY); + if( xShapes3.is()) + { + uno::Sequence<sal_Int32> aNewOrder(maZOrderList.size() + maUnsortedList.size()); + sal_Int32 nIndex = 0; + + for (ZOrderHint& rHint : maZOrderList) + { + // fill in the gaps from unordered list + for (vector<ZOrderHint>::iterator aIt = maUnsortedList.begin(); aIt != maUnsortedList.end() && nIndex < rHint.nShould; ) + { + aNewOrder[nIndex++] = (*aIt).nIs; + aIt = maUnsortedList.erase(aIt); + } + + aNewOrder[nIndex] = rHint.nIs; + nIndex++; + } + + try + { + xShapes3->sort(aNewOrder); + maZOrderList.clear(); + return; + } + catch (const css::lang::IllegalArgumentException& /*e*/) + {} + } + // this is the current index, all shapes before that // index are finished sal_Int32 nIndex = 0; |