[Libreoffice] [PATCH 6/8] Easyhack fdo#38831 remove SvStrings

Brad Sowden code at sowden.org
Thu Dec 29 01:29:34 PST 2011


Hi,

See attached.

Note 1
------
With the for loop below Insert(x,nPos) was previously applied but nPos 
is initialised to the end of vector and is always incremented in every 
loop iteration i.e. Insert(x,nPos) is effectively a push_back(x). Agree?

In "short SvxNumberFormatShell::FillEListWithUserCurrencys(....)"

      size_t nOldListCount = rList.size();
      for( size_t i = 0, nPos = nOldListCount;
           i < static_cast<size_t>(aWSStringsDtor.Count()); ++i )
      {
          bool bFlag = true;
	
	... // code that only impacts bFlag

          if(bFlag)
          {
-            rList.Insert(new String(aInsStr),nPos);
+            rList.push_back( new String(aInsStr) );
              aCurEntryList.insert( aCurEntryList.begin() + (nPos++), 
NUMBERFORMAT_ENTRY_NOT_FOUND);
          }
          else
          {
-            rList.Insert(aList[j],nPos);
-            aList.Remove(j);
+            rList.push_back( aList[j] );
+            aList.erase( aList.begin()+j );
              aCurEntryList.insert( aCurEntryList.begin() + (nPos++), 
aKeyList[j]);
              aKeyList.erase( aKeyList.begin()+j );
          }
      }



Note 2
------
I assume it's safe to cast from short to size_t? There is an existing 
check at the start of the function to ensure the short >= 0.

SvxNumberFormatShell::GetFormat4Entry(short nEntry)
      ...
      if(nEntry < 0)
          return String();
      ...
-        if(aCurrencyFormatList.Count()>nEntry)
+        if( aCurrencyFormatList.size() > static_cast<size_t>(nEntry) )
              return *aCurrencyFormatList[nEntry];


Note 3
------
One function implicitly casted from sal_uInt16 to short. I assume now 
casting from size_t to short doesn't make the situation any worse?

short nSelP = SELPOS_NONE;
...
-            for( sal_uInt16 i=0; i<aCurrencyFormatList.Count(); i++ )
+            for( size_t i=0; i<aCurrencyFormatList.size(); i++ )
              {
...
-                    nSelP = i;
+                    nSelP = static_cast<short>(i);

Regards,
Brad





More information about the LibreOffice mailing list