Date: prev next · Thread: first prev next last
2012 Archives by date, by thread · List index


Hi Michael,

* I used a pointer to the vector as the move() function previously
copied and cleared all elements whereas a pointer swap would suffice.

ah that's why, i had wondered....
would it be possible to use std::swap on the vector itself rather than
the pointer?   i could imagine that being implemented efficiently, and
it would allow the vector to not be a pointer, which is simpler.

also (but that was a pre-existing condition, not really your fault)
member names should start with "m_" so it's easy to grep for member access.

Ah, I can use vector::swap(). Patch attached getting rid of the vector pointer. Much nicer.

Thanks,
Brad
From 7c6b510fdfd2cdc99f8628637296c7fb8622f8d9 Mon Sep 17 00:00:00 2001
From: Brad Sowden <code@sowden.org>
Date: Wed, 6 Jun 2012 18:34:01 +1200
Subject: [PATCH] Use a vector rather than a pointer to a vector

Change-Id: I437a665ffa225ce69e10f7ee71ff2902c3db505e
---
 sw/source/ui/docvw/edtwin.cxx |   59 ++++++++++++++++++----------------------
 1 files changed, 27 insertions(+), 32 deletions(-)

diff --git a/sw/source/ui/docvw/edtwin.cxx b/sw/source/ui/docvw/edtwin.cxx
index fffe6c3..b923ec5 100644
--- a/sw/source/ui/docvw/edtwin.cxx
+++ b/sw/source/ui/docvw/edtwin.cxx
@@ -272,36 +272,31 @@ public:
 
 struct QuickHelpData
 {
-    std::vector<String> *pHelpStrings;
+    std::vector<String> m_aHelpStrings;
     sal_uInt16* pAttrs;
     CommandExtTextInputData* pCETID;
     sal_uLong nTipId;
     sal_uInt16 nLen, nCurArrPos;
     sal_Bool bClear : 1, bChkInsBlank : 1, bIsTip : 1, bIsAutoText : 1;
 
-    QuickHelpData() : pAttrs( 0 ), pCETID( 0 )
-    {
-        pHelpStrings = new std::vector<String>;
-        ClearCntnt();
-    }
-    ~QuickHelpData() { delete pHelpStrings; }
+    QuickHelpData() : pAttrs( 0 ), pCETID( 0 ) { ClearCntnt(); }
 
     void Move( QuickHelpData& rCpy );
     void ClearCntnt();
     void Start( SwWrtShell& rSh, sal_uInt16 nWrdLen );
     void Stop( SwWrtShell& rSh );
 
-    sal_Bool HasCntnt() const { return !pHelpStrings->empty() && 0 != nLen; }
+    sal_Bool HasCntnt() const { return !m_aHelpStrings.empty() && 0 != nLen; }
 
     void Inc( sal_Bool bEndLess )
     {
-        if( ++nCurArrPos >= pHelpStrings->size() )
+        if( ++nCurArrPos >= m_aHelpStrings.size() )
             nCurArrPos = (bEndLess && !bIsAutoText ) ? 0 : nCurArrPos-1;
     }
     void Dec( sal_Bool bEndLess )
     {
         if( 0 == nCurArrPos-- )
-            nCurArrPos = (bEndLess && !bIsAutoText ) ?  pHelpStrings->size()-1 : 0;
+            nCurArrPos = (bEndLess && !bIsAutoText ) ? m_aHelpStrings.size()-1 : 0;
     }
     void FillStrArr( SwWrtShell& rSh, const String& rWord );
     void SortAndFilter();
@@ -2475,7 +2470,7 @@ KEYINPUT_CHECKTABLE_INSDEL:
                 // replace the word or abbreviation with the auto text
                 rSh.StartUndo( UNDO_START );
 
-                String sFnd( (*aTmpQHD.pHelpStrings)[ aTmpQHD.nCurArrPos ] );
+                String sFnd( aTmpQHD.m_aHelpStrings[ aTmpQHD.nCurArrPos ] );
                 if( aTmpQHD.bIsAutoText )
                 {
                     SwGlossaryList* pList = ::GetGlossaryList();
@@ -5471,8 +5466,8 @@ uno::Reference< ::com::sun::star::accessibility::XAccessible > 
SwEditWin::Create
 
 void QuickHelpData::Move( QuickHelpData& rCpy )
 {
-    pHelpStrings->clear();
-    std::swap( pHelpStrings, rCpy.pHelpStrings );
+    m_aHelpStrings.clear();
+    m_aHelpStrings.swap( rCpy.m_aHelpStrings );
 
     bClear = rCpy.bClear;
     nLen = rCpy.nLen;
@@ -5495,7 +5490,7 @@ void QuickHelpData::ClearCntnt()
     nLen = nCurArrPos = 0;
     bClear = bChkInsBlank = sal_False;
     nTipId = 0;
-    pHelpStrings->clear();
+    m_aHelpStrings.clear();
     bIsTip = sal_True;
     bIsAutoText = sal_True;
     delete pCETID, pCETID = 0;
@@ -5524,12 +5519,12 @@ void QuickHelpData::Start( SwWrtShell& rSh, sal_uInt16 nWrdLen )
                     rSh.GetCharRect().Pos() )));
         aPt.Y() -= 3;
         nTipId = Help::ShowTip( &rWin, Rectangle( aPt, Size( 1, 1 )),
-                        (*pHelpStrings)[ nCurArrPos ],
+                        m_aHelpStrings[ nCurArrPos ],
                         QUICKHELP_LEFT | QUICKHELP_BOTTOM );
     }
     else
     {
-        String sStr( (*pHelpStrings)[ nCurArrPos ] );
+        String sStr( m_aHelpStrings[ nCurArrPos ] );
         sStr.Erase( 0, nLen );
         sal_uInt16 nL = sStr.Len();
         pAttrs = new sal_uInt16[ nL ];
@@ -5609,17 +5604,17 @@ void QuickHelpData::FillStrArr( SwWrtShell& rSh, const String& rWord )
                 == sWordLower )
             {
                 if ( aWordCase == CASE_LOWER )
-                    pHelpStrings->push_back( rCC.lowercase( rStr ) );
+                    m_aHelpStrings.push_back( rCC.lowercase( rStr ) );
                 else if ( aWordCase == CASE_SENTENCE )
                 {
                     String sTmp = rCC.lowercase( rStr );
                     sTmp.SetChar( 0, rStr.GetChar(0) );
-                    pHelpStrings->push_back( sTmp );
+                    m_aHelpStrings.push_back( sTmp );
                 }
                 else if ( aWordCase == CASE_UPPER )
-                    pHelpStrings->push_back( rCC.uppercase( rStr ) );
+                    m_aHelpStrings.push_back( rCC.uppercase( rStr ) );
                 else // CASE_OTHER - use retrieved capitalization
-                    pHelpStrings->push_back( rStr );
+                    m_aHelpStrings.push_back( rStr );
             }
         }
         // Data for second loop iteration
@@ -5640,17 +5635,17 @@ void QuickHelpData::FillStrArr( SwWrtShell& rSh, const String& rWord )
             if ( rStr.Len() > rWord.Len() )
             {
                 if ( aWordCase == CASE_LOWER )
-                    pHelpStrings->push_back( rCC.lowercase( rStr ) );
+                    m_aHelpStrings.push_back( rCC.lowercase( rStr ) );
                 else if ( aWordCase == CASE_SENTENCE )
                 {
                     String sTmp = rCC.lowercase( rStr );
                     sTmp.SetChar( 0, rStr.GetChar(0) );
-                    pHelpStrings->push_back( sTmp );
+                    m_aHelpStrings.push_back( sTmp );
                 }
                 else if ( aWordCase == CASE_UPPER )
-                    pHelpStrings->push_back( rCC.uppercase( rStr ) );
+                    m_aHelpStrings.push_back( rCC.uppercase( rStr ) );
                 else // CASE_OTHER - use retrieved capitalization
-                    pHelpStrings->push_back( rStr );
+                    m_aHelpStrings.push_back( rStr );
             }
         }
     }
@@ -5679,14 +5674,14 @@ struct EqualIgnoreCaseAscii
 // TODO - implement an i18n aware sort
 void QuickHelpData::SortAndFilter()
 {
-    std::sort( pHelpStrings->begin(),
-               pHelpStrings->end(),
+    std::sort( m_aHelpStrings.begin(),
+               m_aHelpStrings.end(),
                CompareIgnoreCaseAscii() );
 
-    std::vector<String>::iterator it = std::unique( pHelpStrings->begin(),
-                                                    pHelpStrings->end(),
+    std::vector<String>::iterator it = std::unique( m_aHelpStrings.begin(),
+                                                    m_aHelpStrings.end(),
                                                     EqualIgnoreCaseAscii() );
-    pHelpStrings->erase( it, pHelpStrings->end() );
+    m_aHelpStrings.erase( it, m_aHelpStrings.end() );
 
     nCurArrPos = 0;
 }
@@ -5700,10 +5695,10 @@ void SwEditWin::ShowAutoTextCorrectQuickHelp(
     if( pACfg->IsAutoTextTip() )
     {
         SwGlossaryList* pList = ::GetGlossaryList();
-        pList->HasLongName( rWord, pQuickHlpData->pHelpStrings );
+        pList->HasLongName( rWord, &pQuickHlpData->m_aHelpStrings );
     }
 
-    if( !pQuickHlpData->pHelpStrings->empty() )
+    if( !pQuickHlpData->m_aHelpStrings.empty() )
     {
         pQuickHlpData->bIsTip = sal_True;
         pQuickHlpData->bIsAutoText = sal_True;
@@ -5719,7 +5714,7 @@ void SwEditWin::ShowAutoTextCorrectQuickHelp(
     }
 
 
-    if( !pQuickHlpData->pHelpStrings->empty() )
+    if( !pQuickHlpData->m_aHelpStrings.empty() )
     {
         pQuickHlpData->SortAndFilter();
         pQuickHlpData->Start( rSh, rWord.Len() );
-- 
1.7.7.6


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.