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

Noel Grandin noel.grandin at collabora.co.uk
Thu Mar 15 10:48:54 UTC 2018


 sw/inc/PostItMgr.hxx                 |   11 +----------
 sw/source/uibase/docvw/PostItMgr.cxx |   26 +++++++++++++-------------
 2 files changed, 14 insertions(+), 23 deletions(-)

New commits:
commit 426d55c1a9510be5a95950a94d40463cf4f178fa
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Thu Mar 15 11:48:34 2018 +0200

    loplugin:useuniqueptr in SwPostItPageItem
    
    since we're unconditionally allocating this list, just declare it
    inline.
    And make it a std::vector instead of a std::list, it very inefficient
    storing pointers in a linked list
    
    Change-Id: I715868265f9f2e633395f474267e84ee87356726
    Reviewed-on: https://gerrit.libreoffice.org/51317
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sw/inc/PostItMgr.hxx b/sw/inc/PostItMgr.hxx
index 1f60c50c15a8..2c801fd6886d 100644
--- a/sw/inc/PostItMgr.hxx
+++ b/sw/inc/PostItMgr.hxx
@@ -69,25 +69,16 @@ namespace i18nutil { struct SearchOptions2; }
 #define COL_NOTES_SIDEPANE_ARROW_ENABLED    Color(0,0,0)
 #define COL_NOTES_SIDEPANE_ARROW_DISABLED   Color(172,168,153)
 
-typedef std::list<SwSidebarItem*> SwSidebarItem_list;
-
 struct SwPostItPageItem
 {
     bool bScrollbar;
     sw::sidebarwindows::SidebarPosition eSidebarPosition;
     long lOffset;
     SwRect mPageRect;
-    SwSidebarItem_list* mList;
+    std::vector<SwSidebarItem*> mvSidebarItems;
     SwPostItPageItem(): bScrollbar(false), eSidebarPosition( sw::sidebarwindows::SidebarPosition::LEFT ), lOffset(0)
     {
-        mList = new SwSidebarItem_list;
-    }
-    ~SwPostItPageItem()
-    {
-        mList->clear();
-        delete mList;
     }
-
 };
 
 struct FieldShadowState
diff --git a/sw/source/uibase/docvw/PostItMgr.cxx b/sw/source/uibase/docvw/PostItMgr.cxx
index f0f76560218e..2cd8d420db70 100644
--- a/sw/source/uibase/docvw/PostItMgr.cxx
+++ b/sw/source/uibase/docvw/PostItMgr.cxx
@@ -604,7 +604,7 @@ bool SwPostItMgr::CalcRects()
                 for (unsigned int j=0; j<aPageNum - nNumberOfPages; ++j)
                     mPages.push_back( new SwPostItPageItem());
             }
-            mPages[aPageNum-1]->mList->push_back(pItem);
+            mPages[aPageNum-1]->mvSidebarItems.push_back(pItem);
             mPages[aPageNum-1]->mPageRect = pItem->maLayoutInfo.mPageFrame;
             mPages[aPageNum-1]->eSidebarPosition = pItem->maLayoutInfo.meSidebarPosition;
         }
@@ -665,7 +665,7 @@ void SwPostItMgr::PreparePageContainer()
     // only clear the list, DO NOT delete the objects itself
     for (auto const& page : mPages)
     {
-        page->mList->clear();
+        page->mvSidebarItems.clear();
         if (mvPostItFields.empty())
             page->bScrollbar = false;
     }
@@ -689,14 +689,14 @@ void SwPostItMgr::LayoutPostIts()
         for (SwPostItPageItem* pPage : mPages)
         {
             // only layout if there are notes on this page
-            if (pPage->mList->size()>0)
+            if (pPage->mvSidebarItems.size()>0)
             {
                 std::list<SwAnnotationWin*> aVisiblePostItList;
                 unsigned long           lNeededHeight = 0;
                 long                    mlPageBorder = 0;
                 long                    mlPageEnd = 0;
 
-                for (auto const& pItem : *pPage->mList)
+                for (auto const& pItem : pPage->mvSidebarItems)
                 {
                     VclPtr<SwAnnotationWin> pPostIt = pItem->pPostIt;
 
@@ -929,13 +929,13 @@ void SwPostItMgr::LayoutPostIts()
 
 bool SwPostItMgr::BorderOverPageBorder(unsigned long aPage) const
 {
-    if ( mPages[aPage-1]->mList->empty() )
+    if ( mPages[aPage-1]->mvSidebarItems.empty() )
     {
         OSL_FAIL("Notes SidePane painted but no rects and page lists calculated!");
         return false;
     }
 
-    auto aItem = mPages[aPage-1]->mList->end();
+    auto aItem = mPages[aPage-1]->mvSidebarItems.end();
     --aItem;
     OSL_ENSURE ((*aItem)->pPostIt,"BorderOverPageBorder: NULL postIt, should never happen");
     if ((*aItem)->pPostIt)
@@ -953,7 +953,7 @@ void SwPostItMgr::DrawNotesForPage(OutputDevice *pOutDev, sal_uInt32 nPage)
     assert(nPage < mPages.size());
     if (nPage >= mPages.size())
         return;
-    for (auto const& pItem : *mPages[nPage]->mList)
+    for (auto const& pItem : mPages[nPage]->mvSidebarItems)
     {
         SwAnnotationWin* pPostIt = pItem->pPostIt;
         if (!pPostIt)
@@ -1000,7 +1000,7 @@ void SwPostItMgr::Scroll(const long lScroll,const unsigned long aPage)
     const bool bOldUp = ArrowEnabled(KEY_PAGEUP,aPage);
     const bool bOldDown = ArrowEnabled(KEY_PAGEDOWN,aPage);
     const long aSidebarheight = mpEditWin->PixelToLogic(Size(0,GetSidebarScrollerHeight())).Height();
-    for (auto const& item : *mPages[aPage-1]->mList)
+    for (auto const& item : mPages[aPage-1]->mvSidebarItems)
     {
         SwAnnotationWin* pPostIt = item->pPostIt;
         // if this is an answer, we should take the normal position and not the real, slightly moved position
@@ -1071,7 +1071,7 @@ void SwPostItMgr::MakeVisible(const SwAnnotationWin* pPostIt )
     std::vector<SwPostItPageItem*>::size_type n=0;
     for (auto const& page : mPages)
     {
-        for (auto const& item : *page->mList)
+        for (auto const& item : page->mvSidebarItems)
         {
             if (item->pPostIt==pPostIt)
             {
@@ -1728,13 +1728,13 @@ long SwPostItMgr::GetNextBorder()
 {
     for (auto const& pPage : mPages)
     {
-        for(auto b = pPage->mList->begin(); b!= pPage->mList->end(); ++b)
+        for(auto b = pPage->mvSidebarItems.begin(); b!= pPage->mvSidebarItems.end(); ++b)
         {
             if ((*b)->pPostIt == mpActivePostIt)
             {
                 auto aNext = b;
                 ++aNext;
-                bool bFollow = (aNext != pPage->mList->end()) && (*aNext)->pPostIt->IsFollow();
+                bool bFollow = (aNext != pPage->mvSidebarItems.end()) && (*aNext)->pPostIt->IsFollow();
                 if ( pPage->bScrollbar || bFollow )
                 {
                     return -1;
@@ -1742,7 +1742,7 @@ long SwPostItMgr::GetNextBorder()
                 else
                 {
                     //if this is the last item, return the bottom border otherwise the next item
-                    if (aNext == pPage->mList->end())
+                    if (aNext == pPage->mvSidebarItems.end())
                         return mpEditWin->LogicToPixel(Point(0,pPage->mPageRect.Bottom())).Y() - GetSpaceBetween();
                     else
                         return (*aNext)->pPostIt->GetPosPixel().Y() - GetSpaceBetween();
@@ -1974,7 +1974,7 @@ void SwPostItMgr::CorrectPositions()
         long aAnchorPosY = 0;
         for (SwPostItPageItem* pPage : mPages)
         {
-            for (auto const& item : *pPage->mList)
+            for (auto const& item : pPage->mvSidebarItems)
             {
                 // check, if anchor overlay object exists.
                 if ( item->bShow && item->pPostIt && item->pPostIt->Anchor() )


More information about the Libreoffice-commits mailing list