svx/source/sdr/primitive2d/sdrframeborderprimitive2d.cxx | 80 +++++++-------- 1 file changed, 38 insertions(+), 42 deletions(-)
New commits: commit f73d57b260aa8722df42225c279f24cba0699213 Author: Luboš Luňák <l.lu...@collabora.com> AuthorDate: Wed Apr 7 15:29:39 2021 +0200 Commit: Luboš Luňák <l.lu...@collabora.com> CommitDate: Wed Apr 7 16:59:19 2021 +0200 avoid pointless O(N^2) dynamic_cast I already tried to reduce the cost of this in ef4964a4e598c3c97, but back then I missed the fact that in fact all the casts guaranteed. So partially revert the first commit and simply use static_cast. Change-Id: I4231f698119d56e9f2536f2f0c9d824442d76b09 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113736 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lu...@collabora.com> diff --git a/svx/source/sdr/primitive2d/sdrframeborderprimitive2d.cxx b/svx/source/sdr/primitive2d/sdrframeborderprimitive2d.cxx index 6e289d4be3f1..b87cfcd9342c 100644 --- a/svx/source/sdr/primitive2d/sdrframeborderprimitive2d.cxx +++ b/svx/source/sdr/primitive2d/sdrframeborderprimitive2d.cxx @@ -797,55 +797,51 @@ namespace drawinglayer::primitive2d for(const auto& aCandidatePartial : aPartial) { - bool bDidMerge(false); - - // This algorithm is O(N^2) and repeated dynamic_cast inside would be quite costly. - // So check first and skip if the primitives aren't BorderLinePrimitive2D. - const drawinglayer::primitive2d::BorderLinePrimitive2D* candidatePartialAsBorder - = dynamic_cast<const drawinglayer::primitive2d::BorderLinePrimitive2D*>(aCandidatePartial.get()); - if(candidatePartialAsBorder) + if(aRetval.empty()) + { + // no local data yet, just add as 1st entry, done + aRetval.append(aCandidatePartial); + } + else { + bool bDidMerge(false); + for(auto& aCandidateRetval : aRetval) { - const drawinglayer::primitive2d::BorderLinePrimitive2D* candidateRetvalAsBorder - = dynamic_cast<const drawinglayer::primitive2d::BorderLinePrimitive2D*>(aCandidateRetval.get()); - if(candidateRetvalAsBorder) + // try to merge by appending new data to existing data + const drawinglayer::primitive2d::Primitive2DReference aMergeRetvalPartial( + drawinglayer::primitive2d::tryMergeBorderLinePrimitive2D( + static_cast<BorderLinePrimitive2D*>(aCandidateRetval.get()), + static_cast<BorderLinePrimitive2D*>(aCandidatePartial.get()))); + + if(aMergeRetvalPartial.is()) + { + // could append, replace existing data with merged data, done + aCandidateRetval = aMergeRetvalPartial; + bDidMerge = true; + break; + } + + // try to merge by appending existing data to new data + const drawinglayer::primitive2d::Primitive2DReference aMergePartialRetval( + drawinglayer::primitive2d::tryMergeBorderLinePrimitive2D( + static_cast<BorderLinePrimitive2D*>(aCandidatePartial.get()), + static_cast<BorderLinePrimitive2D*>(aCandidateRetval.get()))); + + if(aMergePartialRetval.is()) { - // try to merge by appending new data to existing data - const drawinglayer::primitive2d::Primitive2DReference aMergeRetvalPartial( - drawinglayer::primitive2d::tryMergeBorderLinePrimitive2D( - candidateRetvalAsBorder, - candidatePartialAsBorder)); - - if(aMergeRetvalPartial.is()) - { - // could append, replace existing data with merged data, done - aCandidateRetval = aMergeRetvalPartial; - bDidMerge = true; - break; - } - - // try to merge by appending existing data to new data - const drawinglayer::primitive2d::Primitive2DReference aMergePartialRetval( - drawinglayer::primitive2d::tryMergeBorderLinePrimitive2D( - candidatePartialAsBorder, - candidateRetvalAsBorder)); - - if(aMergePartialRetval.is()) - { - // could append, replace existing data with merged data, done - aCandidateRetval = aMergePartialRetval; - bDidMerge = true; - break; - } + // could append, replace existing data with merged data, done + aCandidateRetval = aMergePartialRetval; + bDidMerge = true; + break; } } - } - if(!bDidMerge) - { - // no merge after checking all existing data, append as new segment - aRetval.append(aCandidatePartial); + if(!bDidMerge) + { + // no merge after checking all existing data, append as new segment + aRetval.append(aCandidatePartial); + } } } } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits