[Libreoffice-commits] core.git: include/svx svx/source sw/inc sw/source

Tor Lillqvist tml at collabora.com
Tue Dec 19 19:43:40 UTC 2017


 include/svx/svdobj.hxx                                      |    3 +
 svx/source/svdraw/svdobj.cxx                                |    5 ++
 sw/inc/textboxhelper.hxx                                    |    2 -
 sw/source/core/doc/textboxhelper.cxx                        |   21 ++++--------
 sw/source/core/draw/dflyobj.cxx                             |    6 +++
 sw/source/core/frmedt/feshview.cxx                          |    2 -
 sw/source/core/inc/dflyobj.hxx                              |    2 +
 sw/source/core/objectpositioning/anchoredobjectposition.cxx |    2 -
 8 files changed, 26 insertions(+), 17 deletions(-)

New commits:
commit fdbd3ac1880b3943e2cff48ecfb95dd088210d09
Author: Tor Lillqvist <tml at collabora.com>
Date:   Mon Dec 18 17:49:59 2017 +0200

    Get rid of a dynamic_cast
    
    Add a virtual member function instead. This improves performance a
    bit. The time to load a specific pathological customer document
    dropped from 1min 53s to 1min 47s on my machine. Not hugely, but
    clearly.
    
    Change-Id: I1e59d601e9d0e14b6a756c6e0ad29ce2a1fce66d
    Reviewed-on: https://gerrit.libreoffice.org/46791
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Tor Lillqvist <tml at collabora.com>

diff --git a/include/svx/svdobj.hxx b/include/svx/svdobj.hxx
index f1768787c92a..265ec9b96c72 100644
--- a/include/svx/svdobj.hxx
+++ b/include/svx/svdobj.hxx
@@ -801,6 +801,9 @@ public:
 
     virtual void dumpAsXml(struct _xmlTextWriter* pWriter) const;
 
+    /// Is this a textbox of a drawinglayer shape?
+    virtual bool IsTextBox() const;
+
     void SetEmptyPresObj(bool bEpt);
     bool IsEmptyPresObj() const { return bEmptyPresObj;}
     void SetNotVisibleAsMaster(bool bFlg);
diff --git a/svx/source/svdraw/svdobj.cxx b/svx/source/svdraw/svdobj.cxx
index 4744dd2c1d9b..b0587cfe4e97 100644
--- a/svx/source/svdraw/svdobj.cxx
+++ b/svx/source/svdraw/svdobj.cxx
@@ -3065,6 +3065,11 @@ bool SdrObject::HasText() const
     return false;
 }
 
+bool SdrObject::IsTextBox() const
+{
+    return false;
+}
+
 SdrDelayBroadcastObjectChange::SdrDelayBroadcastObjectChange( SdrObject& rObj ) :
     mrObj(rObj), mbOldDelayBroadcastObjectChange( rObj.mbDelayBroadcastObjectChange)
 {
diff --git a/sw/inc/textboxhelper.hxx b/sw/inc/textboxhelper.hxx
index 189b7c006c96..0c3bf5ff742b 100644
--- a/sw/inc/textboxhelper.hxx
+++ b/sw/inc/textboxhelper.hxx
@@ -89,8 +89,6 @@ public:
      *              Valid types are RES_DRAWFRMFMT and RES_FLYFRMFMT.
      */
     static bool isTextBox(const SwFrameFormat* pFormat, sal_uInt16 nType);
-    /// Is pObject a textbox of a drawinglayer shape?
-    static bool isTextBox(const SdrObject* pObject);
 
     /// Count number of shapes in the document, excluding TextBoxes.
     static sal_Int32 getCount(const SwDoc* pDoc);
diff --git a/sw/source/core/doc/textboxhelper.cxx b/sw/source/core/doc/textboxhelper.cxx
index 050d5339961c..7ec48abc9eaa 100644
--- a/sw/source/core/doc/textboxhelper.cxx
+++ b/sw/source/core/doc/textboxhelper.cxx
@@ -147,20 +147,13 @@ bool SwTextBoxHelper::isTextBox(const SwFrameFormat* pFormat, sal_uInt16 nType)
     return pOtherFormat->GetAttrSet().HasItem(RES_CNTNT) && pOtherFormat->GetContent() == rContent;
 }
 
-bool SwTextBoxHelper::isTextBox(const SdrObject* pObject)
-{
-    auto pVirtFlyDrawObj = dynamic_cast<const SwVirtFlyDrawObj*>(pObject);
-    if (!pVirtFlyDrawObj)
-        return false;
-    return isTextBox(pVirtFlyDrawObj->GetFormat(), RES_FLYFRMFMT);
-}
-
 sal_Int32 SwTextBoxHelper::getCount(SdrPage const* pPage)
 {
     sal_Int32 nRet = 0;
     for (std::size_t i = 0; i < pPage->GetObjCount(); ++i)
     {
-        if (isTextBox(pPage->GetObj(i)))
+        SdrObject* p = pPage->GetObj(i);
+        if (p && p->IsTextBox())
             continue;
         ++nRet;
     }
@@ -188,11 +181,12 @@ uno::Any SwTextBoxHelper::getByIndex(SdrPage const* pPage, sal_Int32 nIndex)
     sal_Int32 nCount = 0; // Current logical index.
     for (std::size_t i = 0; i < pPage->GetObjCount(); ++i)
     {
-        if (isTextBox(pPage->GetObj(i)))
+        SdrObject* p = pPage->GetObj(i);
+        if (p && p->IsTextBox())
             continue;
         if (nCount == nIndex)
         {
-            pRet = pPage->GetObj(i);
+            pRet = p;
             break;
         }
         ++nCount;
@@ -211,9 +205,10 @@ sal_Int32 SwTextBoxHelper::getOrdNum(const SdrObject* pObject)
         sal_Int32 nOrder = 0; // Current logical order.
         for (std::size_t i = 0; i < pPage->GetObjCount(); ++i)
         {
-            if (isTextBox(pPage->GetObj(i)))
+            SdrObject* p = pPage->GetObj(i);
+            if (p && p->IsTextBox())
                 continue;
-            if (pPage->GetObj(i) == pObject)
+            if (p == pObject)
                 return nOrder;
             ++nOrder;
         }
diff --git a/sw/source/core/draw/dflyobj.cxx b/sw/source/core/draw/dflyobj.cxx
index a0414846977d..e149fbf1d94a 100644
--- a/sw/source/core/draw/dflyobj.cxx
+++ b/sw/source/core/draw/dflyobj.cxx
@@ -47,6 +47,7 @@
 #include <grfatr.hxx>
 #include <pagefrm.hxx>
 #include <rootfrm.hxx>
+#include <textboxhelper.hxx>
 #include <wrtsh.hxx>
 #include <ndgrf.hxx>
 #include <frmmgr.hxx>
@@ -1275,4 +1276,9 @@ SdrObject* SwVirtFlyDrawObj::CheckMacroHit( const SdrObjMacroHitRec& rRec ) cons
     return SdrObject::CheckMacroHit( rRec );
 }
 
+bool SwVirtFlyDrawObj::IsTextBox() const
+{
+    return SwTextBoxHelper::isTextBox(GetFormat(), RES_FLYFRMFMT);
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/frmedt/feshview.cxx b/sw/source/core/frmedt/feshview.cxx
index 4ab50d4ab383..616c00e64c83 100644
--- a/sw/source/core/frmedt/feshview.cxx
+++ b/sw/source/core/frmedt/feshview.cxx
@@ -1533,7 +1533,7 @@ const SdrObject* SwFEShell::GetBestObject( bool bNext, GotoObjFlags eType, bool
                 // Ignore TextBoxes of draw shapes here, so that
                 // SwFEShell::SelectObj() won't jump back on this list, meaning
                 // we never jump to the next draw shape.
-                SwTextBoxHelper::isTextBox(pObj) ||
+                (pObj && pObj->IsTextBox()) ||
                 ( eType == GotoObjFlags::DrawSimple && lcl_IsControlGroup( pObj ) ) ||
                 ( eType == GotoObjFlags::DrawControl && !lcl_IsControlGroup( pObj ) ) ||
                 ( pFilter && !pFilter->includeObject( *pObj ) ) )
diff --git a/sw/source/core/inc/dflyobj.hxx b/sw/source/core/inc/dflyobj.hxx
index 77df7060420d..a0cf7fd28d3a 100644
--- a/sw/source/core/inc/dflyobj.hxx
+++ b/sw/source/core/inc/dflyobj.hxx
@@ -128,6 +128,8 @@ public:
 
     // RotGrfFlyFrame: If true, this SdrObject supports only limited rotation.
     virtual bool HasLimitedRotation() const override;
+
+    virtual bool IsTextBox() const override;
 };
 
 #endif
diff --git a/sw/source/core/objectpositioning/anchoredobjectposition.cxx b/sw/source/core/objectpositioning/anchoredobjectposition.cxx
index b1296b5eec13..bd11bac3523d 100644
--- a/sw/source/core/objectpositioning/anchoredobjectposition.cxx
+++ b/sw/source/core/objectpositioning/anchoredobjectposition.cxx
@@ -511,7 +511,7 @@ SwTwips SwAnchoredObjectPosition::ImplAdjustVertRelPos( const SwTwips nTopOfAnch
              && nAdjustedRelPosY < nProposedRelPosY )
         {
             const SwFrameFormat* pFormat = &(GetFrameFormat());
-            if ( SwTextBoxHelper::isTextBox(&GetObject()) )
+            if ( GetObject().IsTextBox() )
             {
                 // shrink textboxes to extend beyond the page bottom
                 SwFrameFormat* pFrameFormat = ::FindFrameFormat(&GetObject());


More information about the Libreoffice-commits mailing list