[Libreoffice-commits] core.git: basctl/source basic/source include/basic sw/source

Arnaud Versini arnaud.versini at gmail.com
Thu Jan 7 04:19:02 PST 2016


 basctl/source/basicide/basides1.cxx |    4 -
 basctl/source/basicide/macrodlg.cxx |    4 -
 basic/source/basmgr/basmgr.cxx      |   34 ++++-----------
 basic/source/classes/sb.cxx         |   78 ++++++++++++++----------------------
 basic/source/classes/sbxmod.cxx     |    7 +--
 basic/source/comp/exprnode.cxx      |    5 --
 include/basic/sbmod.hxx             |    1 
 include/basic/sbstar.hxx            |    6 +-
 sw/source/filter/html/htmlbas.cxx   |   14 ++----
 9 files changed, 61 insertions(+), 92 deletions(-)

New commits:
commit 5e0d36adc3f7f245edfc79230d0871017ba15d5d
Author: Arnaud Versini <arnaud.versini at gmail.com>
Date:   Sat Dec 19 15:18:01 2015 +0100

    BASIC : use std::vector instead of SbArray for Modules.
    
    Change-Id: I9594efb13b3dccc637ccd61eea4b42255c2a775c
    Reviewed-on: https://gerrit.libreoffice.org/20817
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Michael Stahl <mstahl at redhat.com>

diff --git a/basctl/source/basicide/basides1.cxx b/basctl/source/basicide/basides1.cxx
index df3021b..7315853 100644
--- a/basctl/source/basicide/basides1.cxx
+++ b/basctl/source/basicide/basides1.cxx
@@ -302,7 +302,7 @@ void Shell::ExecuteGlobal( SfxRequest& rReq )
                 SbModule* pModule = pBasic->FindModule( rInfo.GetModule() );
                 if ( !pModule )
                 {
-                    if ( !rInfo.GetModule().isEmpty() || !pBasic->GetModules()->Count() )
+                    if ( !rInfo.GetModule().isEmpty() || pBasic->GetModules().empty() )
                     {
                         OUString aModName = rInfo.GetModule();
 
@@ -311,7 +311,7 @@ void Shell::ExecuteGlobal( SfxRequest& rReq )
                             pModule = pBasic->FindModule( aModName );
                     }
                     else
-                        pModule = static_cast<SbModule*>( pBasic->GetModules()->Get(0) );
+                        pModule = pBasic->GetModules().front();
                 }
                 DBG_ASSERT( pModule, "Kein Modul!" );
                 if ( pModule && !pModule->GetMethods()->Find( rInfo.GetMethod(), SbxCLASS_METHOD ) )
diff --git a/basctl/source/basicide/macrodlg.cxx b/basctl/source/basicide/macrodlg.cxx
index 83a5ed4..8979d4d 100644
--- a/basctl/source/basicide/macrodlg.cxx
+++ b/basctl/source/basicide/macrodlg.cxx
@@ -371,8 +371,8 @@ SbMethod* MacroChooser::CreateMacro()
             }
             pModule = pBasic->FindModule( aModName );
         }
-        else if ( pBasic->GetModules()->Count() )
-            pModule = static_cast<SbModule*>(pBasic->GetModules()->Get( 0 ));
+        else if ( !pBasic->GetModules().empty() )
+            pModule = pBasic->GetModules().front();
 
         if ( !pModule )
         {
diff --git a/basic/source/basmgr/basmgr.cxx b/basic/source/basmgr/basmgr.cxx
index 2742a24..8ce26ae 100644
--- a/basic/source/basmgr/basmgr.cxx
+++ b/basic/source/basmgr/basmgr.cxx
@@ -580,12 +580,8 @@ void copyToLibraryContainer( StarBASIC* pBasic, const LibraryContainerInfo& rInf
     if ( !xLib.is() )
         return;
 
-    sal_uInt16 nModCount = pBasic->GetModules()->Count();
-    for ( sal_uInt16 nMod = 0 ; nMod < nModCount ; nMod++ )
+    for ( const auto& pModule: pBasic->GetModules() )
     {
-        SbModule* pModule = static_cast<SbModule*>(pBasic->GetModules()->Get( nMod ));
-        DBG_ASSERT( pModule, "Module not received!" );
-
         OUString aModName = pModule->GetName();
         if( !xLib->hasByName( aModName ) )
         {
@@ -917,14 +913,10 @@ bool BasicManager::HasExeCode( const OUString& sLib )
     StarBASIC* pLib = GetLib(sLib);
     if ( pLib )
     {
-        SbxArray* pMods = pLib->GetModules();
-        sal_uInt16 nMods = pMods ? pMods->Count() : 0;
-        for( sal_uInt16 i = 0; i < nMods; i++ )
+        for (const auto& pModule: pLib->GetModules())
         {
-            SbModule* p = static_cast<SbModule*>( pMods->Get( i ) );
-            if ( p )
-                if ( p->HasExeCode() )
-                    return true;
+            if (pModule->HasExeCode())
+                return true;
         }
     }
     return false;
@@ -1114,9 +1106,8 @@ void BasicManager::CheckModules( StarBASIC* pLib, bool bReference )
     }
     bool bModified = pLib->IsModified();
 
-    for ( sal_uInt16 nMod = 0; nMod < pLib->GetModules()->Count(); nMod++ )
+    for ( const auto& pModule: pLib->GetModules() )
     {
-        SbModule* pModule = static_cast<SbModule*>(pLib->GetModules()->Get( nMod ));
         DBG_ASSERT( pModule, "Module not received!" );
         if ( !pModule->IsCompiled() && !StarBASIC::GetErrorCode() )
         {
@@ -1601,11 +1592,9 @@ namespace
 
                 if( pLib )
                 {
-                    sal_uInt16 nModCount = pLib->GetModules()->Count();
-                    for( sal_uInt16 nMod = 0; nMod < nModCount; ++nMod )
+                    for ( const auto& pMod: pLib->GetModules() )
                     {
-                        SbModule* pMod = static_cast<SbModule*>(pLib->GetModules()->Get( nMod ));
-                        if ( pMod && rTransliteration.isEqual( pMod->GetName(), sModule ) )
+                        if ( rTransliteration.isEqual( pMod->GetName(), sModule ) )
                         {
                             SbMethod* pMethod = static_cast<SbMethod*>(pMod->Find( sMacro, SbxCLASS_METHOD ));
                             if( pMethod )
@@ -1827,8 +1816,7 @@ uno::Type ModuleContainer_Impl::getElementType()
 sal_Bool ModuleContainer_Impl::hasElements()
     throw(uno::RuntimeException, std::exception)
 {
-    SbxArray* pMods = mpLib ? mpLib->GetModules() : nullptr;
-    return pMods && pMods->Count() > 0;
+    return mpLib && !mpLib->GetModules().empty();
 }
 
 // Methods XNameAccess
@@ -1848,14 +1836,12 @@ uno::Any ModuleContainer_Impl::getByName( const OUString& aName )
 uno::Sequence< OUString > ModuleContainer_Impl::getElementNames()
     throw(uno::RuntimeException, std::exception)
 {
-    SbxArray* pMods = mpLib ? mpLib->GetModules() : nullptr;
-    sal_uInt16 nMods = pMods ? pMods->Count() : 0;
+    sal_uInt16 nMods = mpLib ? mpLib->GetModules().size() : 0;
     uno::Sequence< OUString > aRetSeq( nMods );
     OUString* pRetSeq = aRetSeq.getArray();
     for( sal_uInt16 i = 0 ; i < nMods ; i++ )
     {
-        SbxVariable* pMod = pMods->Get( i );
-        pRetSeq[i] = OUString( pMod->GetName() );
+        pRetSeq[i] = mpLib->GetModules()[i]->GetName();
     }
     return aRetSeq;
 }
diff --git a/basic/source/classes/sb.cxx b/basic/source/classes/sb.cxx
index 41e9ab0..6b2a78d 100644
--- a/basic/source/classes/sb.cxx
+++ b/basic/source/classes/sb.cxx
@@ -924,7 +924,6 @@ StarBASIC::StarBASIC( StarBASIC* p, bool bIsDocBasic  )
     pLibInfo = nullptr;
     bNoRtl = bBreak = false;
     bVBAEnabled = false;
-    pModules = new SbxArray;
 
     if( !GetSbData()->nInst++ )
     {
@@ -1018,10 +1017,9 @@ void StarBASIC::implClearDependingVarsOnDelete( StarBASIC* pDeletedBasic )
 {
     if( this != pDeletedBasic )
     {
-        for( sal_uInt16 i = 0; i < pModules->Count(); i++ )
+        for( const auto& pModule: pModules)
         {
-            SbModule* p = static_cast<SbModule*>(pModules->Get( i ));
-            p->ClearVarsDependingOnDeletedBasic( pDeletedBasic );
+            pModule->ClearVarsDependingOnDeletedBasic( pDeletedBasic );
         }
     }
 
@@ -1082,7 +1080,7 @@ SbModule* StarBASIC::MakeModule32( const OUString& rName, const ModuleInfo& mInf
     }
     p->SetSource32( rSrc );
     p->SetParent( this );
-    pModules->Insert( p, pModules->Count() );
+    pModules.push_back(p);
     SetModified( true );
     return p;
 }
@@ -1091,7 +1089,7 @@ void StarBASIC::Insert( SbxVariable* pVar )
 {
     if( dynamic_cast<const SbModule*>(pVar) != nullptr)
     {
-        pModules->Insert( pVar, pModules->Count() );
+        pModules.push_back(static_cast<SbModule*>(pVar));
         pVar->SetParent( this );
         StartListening( pVar->GetBroadcaster(), true );
     }
@@ -1112,7 +1110,7 @@ void StarBASIC::Remove( SbxVariable* pVar )
     {
         // #87540 Can be last reference!
         SbxVariableRef xVar = pVar;
-        pModules->Remove( pVar );
+        pModules.erase(std::remove(pModules.begin(), pModules.end(), pVar));
         pVar->SetParent( nullptr );
         EndListening( pVar->GetBroadcaster() );
     }
@@ -1129,20 +1127,16 @@ bool StarBASIC::Compile( SbModule* pMod )
 
 void StarBASIC::Clear()
 {
-    while( pModules->Count() )
-    {
-        pModules->Remove( pModules->Count() - 1 );
-    }
+    pModules.clear();
 }
 
 SbModule* StarBASIC::FindModule( const OUString& rName )
 {
-    for( sal_uInt16 i = 0; i < pModules->Count(); i++ )
+    for (const auto& pModule: pModules)
     {
-        SbModule* p = static_cast<SbModule*>( pModules->Get( i ) );
-        if( p->GetName().equalsIgnoreAsciiCase( rName ) )
+        if( pModule->GetName().equalsIgnoreAsciiCase( rName ) )
         {
-            return p;
+            return pModule.get();
         }
     }
     return nullptr;
@@ -1218,13 +1212,9 @@ void StarBASIC::InitAllModules( StarBASIC* pBasicNotToInit )
     SolarMutexGuard guard;
 
     // Init own modules
-    for ( sal_uInt16 nMod = 0; nMod < pModules->Count(); nMod++ )
+    for (const auto& pModule: pModules)
     {
-        SbModule* pModule = static_cast<SbModule*>( pModules->Get( nMod ) );
-        if( !pModule->IsCompiled() )
-        {
-            pModule->Compile();
-        }
+        pModule->Compile();
     }
     // compile modules first then RunInit ( otherwise there is
     // can be order dependency, e.g. classmodule A has a member
@@ -1233,13 +1223,12 @@ void StarBASIC::InitAllModules( StarBASIC* pBasicNotToInit )
     // Consider required types to init in right order. Class modules
     // that are required by other modules have to be initialized first.
     ModuleInitDependencyMap aMIDMap;
-    for ( sal_uInt16 nMod = 0; nMod < pModules->Count(); nMod++ )
+    for (const auto& pModule: pModules)
     {
-        SbModule* pModule = static_cast<SbModule*>(pModules->Get( nMod ));
         OUString aModuleName = pModule->GetName();
         if( pModule->isProxyModule() )
         {
-            aMIDMap[aModuleName] = ClassModuleRunInitItem( pModule );
+            aMIDMap[aModuleName] = ClassModuleRunInitItem( pModule.get() );
         }
     }
 
@@ -1251,9 +1240,8 @@ void StarBASIC::InitAllModules( StarBASIC* pBasicNotToInit )
     }
 
     // Call RunInit on standard modules
-    for ( sal_uInt16 nMod = 0; nMod < pModules->Count(); nMod++ )
+    for (const auto& pModule: pModules)
     {
-        SbModule* pModule = static_cast<SbModule*>(pModules->Get( nMod ));
         if( !pModule->isProxyModule() )
         {
             pModule->RunInit();
@@ -1278,10 +1266,9 @@ void StarBASIC::InitAllModules( StarBASIC* pBasicNotToInit )
 void StarBASIC::DeInitAllModules()
 {
     // Deinit own modules
-    for ( sal_uInt16 nMod = 0; nMod < pModules->Count(); nMod++ )
+    for (const auto& pModule: pModules)
     {
-        SbModule* pModule = static_cast<SbModule*>(pModules->Get( nMod ));
-        if( pModule->pImage && !pModule->isProxyModule() && nullptr == dynamic_cast<const SbObjModule*>( pModule) )
+        if( pModule->pImage && !pModule->isProxyModule() && nullptr == dynamic_cast<SbObjModule*>( pModule.get()) )
         {
             pModule->pImage->bInit = false;
         }
@@ -1331,34 +1318,33 @@ SbxVariable* StarBASIC::Find( const OUString& rName, SbxClassType t )
     // Search module
     if( !pRes )
     {
-        for( sal_uInt16 i = 0; i < pModules->Count(); i++ )
+        for (const auto& pModule: pModules)
         {
-            SbModule* p = static_cast<SbModule*>( pModules->Get( i ) );
-            if( p->IsVisible() )
+            if( pModule->IsVisible() )
             {
                 // Remember modul fpr Main() call
                 // or is the name equal?!?
-                if( p->GetName().equalsIgnoreAsciiCase( rName ) )
+                if( pModule->GetName().equalsIgnoreAsciiCase( rName ) )
                 {
                     if( t == SbxCLASS_OBJECT || t == SbxCLASS_DONTCARE )
                     {
-                        pRes = p; break;
+                        pRes = pModule.get(); break;
                     }
-                    pNamed = p;
+                    pNamed = pModule.get();
                 }
                 // Only variables qualified by the Module Name e.g. Sheet1.foo
                 // should work for Document && Class type Modules
-                sal_Int32 nType = p->GetModuleType();
+                sal_Int32 nType = pModule->GetModuleType();
                 if ( nType == ModuleType::DOCUMENT || nType == ModuleType::FORM )
                 {
                     continue;
                 }
                 // otherwise check if the element is available
                 // unset GBLSEARCH-Flag (due to Rekursion)
-                SbxFlagBits nGblFlag = p->GetFlags() & SbxFlagBits::GlobalSearch;
-                p->ResetFlag( SbxFlagBits::GlobalSearch );
-                pRes = p->Find( rName, t );
-                p->SetFlag( nGblFlag );
+                SbxFlagBits nGblFlag = pModule->GetFlags() & SbxFlagBits::GlobalSearch;
+                pModule->ResetFlag( SbxFlagBits::GlobalSearch );
+                pRes = pModule->Find( rName, t );
+                pModule->SetFlag( nGblFlag );
                 if( pRes )
                 {
                     break;
@@ -1887,7 +1873,7 @@ bool StarBASIC::LoadData( SvStream& r, sal_uInt16 nVer )
     ppDeleteTab.reset();
 
     sal_uInt16 nMod(0);
-    pModules->Clear();
+    pModules.clear();
     r.ReadUInt16( nMod );
     const size_t nMinSbxSize(14);
     const size_t nMaxPossibleEntries = r.remainingSize() / nMinSbxSize;
@@ -1913,7 +1899,7 @@ bool StarBASIC::LoadData( SvStream& r, sal_uInt16 nVer )
         else
         {
             pMod->SetParent( this );
-            pModules->Put( pMod, i );
+            pModules.push_back( pMod );
         }
     }
     // HACK for SFX-Bullshit!
@@ -1940,11 +1926,11 @@ bool StarBASIC::StoreData( SvStream& r ) const
     {
         return false;
     }
-    r.WriteUInt16( pModules->Count() );
-    for( sal_uInt16 i = 0; i < pModules->Count(); i++ )
+    assert(pModules.size() < SAL_MAX_UINT16);
+    r.WriteUInt16( static_cast<sal_uInt16>(pModules.size()));
+    for( const auto& rpModule: pModules )
     {
-        SbModule* p = static_cast<SbModule*>( pModules->Get( i ) );
-        if( !p->Store( r ) )
+        if( !rpModule->Store( r ) )
         {
             return false;
         }
diff --git a/basic/source/classes/sbxmod.cxx b/basic/source/classes/sbxmod.cxx
index 2834dd2..c025a9c 100644
--- a/basic/source/classes/sbxmod.cxx
+++ b/basic/source/classes/sbxmod.cxx
@@ -1400,12 +1400,11 @@ void SbModule::ClearVarsDependingOnDeletedBasic( StarBASIC* pDeletedBasic )
 void StarBASIC::ClearAllModuleVars()
 {
     // Initialise the own module
-    for ( sal_uInt16 nMod = 0; nMod < pModules->Count(); nMod++ )
+    for (const auto& rModule: pModules)
     {
-        SbModule* pModule = static_cast<SbModule*>(pModules->Get( nMod ));
         // Initialise only, if the startcode was already executed
-        if( pModule->pImage && pModule->pImage->bInit && !pModule->isProxyModule() && nullptr == dynamic_cast<const SbObjModule*>( pModule) )
-            pModule->ClearPrivateVars();
+        if( rModule->pImage && rModule->pImage->bInit && !rModule->isProxyModule() && nullptr == dynamic_cast<const SbObjModule*>( rModule.get()) )
+            rModule->ClearPrivateVars();
     }
 
 }
diff --git a/basic/source/comp/exprnode.cxx b/basic/source/comp/exprnode.cxx
index 9d77f6d..19272dc 100644
--- a/basic/source/comp/exprnode.cxx
+++ b/basic/source/comp/exprnode.cxx
@@ -19,6 +19,7 @@
 
 
 #include <math.h>
+#include <algorithm>
 
 #include <rtl/math.hxx>
 #include "codegen.hxx"
@@ -191,9 +192,7 @@ short SbiExprNode::GetDepth()
     if( IsOperand() ) return 0;
     else
     {
-        short d1 = pLeft->GetDepth();
-        short d2 = pRight->GetDepth();
-        return( (d1 < d2 ) ? d2 : d1 ) + 1;
+        return std::max(pLeft->GetDepth(), pRight->GetDepth()) + 1;
     }
 }
 
diff --git a/include/basic/sbmod.hxx b/include/basic/sbmod.hxx
index 5dfe5f0..95e1bdb 100644
--- a/include/basic/sbmod.hxx
+++ b/include/basic/sbmod.hxx
@@ -136,6 +136,7 @@ public:
 };
 
 typedef tools::SvRef<SbModule> SbModuleRef;
+typedef std::vector<SbModuleRef> SbModules;
 
 // Object class for instances of class modules
 class BASIC_DLLPUBLIC SbClassModuleObject : public SbModule
diff --git a/include/basic/sbstar.hxx b/include/basic/sbstar.hxx
index 8c02be3..0f59a5c 100644
--- a/include/basic/sbstar.hxx
+++ b/include/basic/sbstar.hxx
@@ -22,6 +22,7 @@
 
 #include <basic/sbx.hxx>
 #include <basic/sbxobj.hxx>
+#include <basic/sbmod.hxx>
 #include <rtl/ustring.hxx>
 #include <osl/mutex.hxx>
 #include <tools/link.hxx>
@@ -32,7 +33,6 @@
 #include <com/sun/star/frame/XModel.hpp>
 #include <basic/basicdllapi.h>
 
-class SbModule;                     // completed module
 class SbiInstance;                  // runtime instance
 class SbiRuntime;                   // currently running procedure
 class SbiImage;                     // compiled image
@@ -49,7 +49,7 @@ class BASIC_DLLPUBLIC StarBASIC : public SbxObject
     friend class SbiRuntime;
     friend class DocBasicItem;
 
-    SbxArrayRef     pModules;               // List of all modules
+    SbModules       pModules;               // List of all modules
     SbxObjectRef    pRtl;               // Runtime Library
     SbxArrayRef     xUnoListeners;          // Listener handled by CreateUnoListener
 
@@ -117,7 +117,7 @@ public:
     virtual SbxVariable* Find( const OUString&, SbxClassType ) override;
     virtual bool Call( const OUString&, SbxArray* = nullptr ) override;
 
-    SbxArray*       GetModules() { return pModules; }
+    SbModules&      GetModules() { return pModules; }
     SbxObject*      GetRtl()     { return pRtl;     }
     SbModule*       FindModule( const OUString& );
     // Run init code of all modules (including the inserted Doc-Basics)
diff --git a/sw/source/filter/html/htmlbas.cxx b/sw/source/filter/html/htmlbas.cxx
index 7489859..ef2f83b 100644
--- a/sw/source/filter/html/htmlbas.cxx
+++ b/sw/source/filter/html/htmlbas.cxx
@@ -268,23 +268,21 @@ void SwHTMLWriter::OutBasic()
         return;
     }
 
+    bool bFirst=true;
     // und jetzt alle StarBasic-Module und alle unbenutzen JavaSrript-Module
     // ausgeben
     for( sal_uInt16 i=0; i<pBasicMan->GetLibCount(); i++ )
     {
         StarBASIC *pBasic = pBasicMan->GetLib( i  );
         const OUString& rLibName = pBasic->GetName();
-
-        SbxArray *pModules = pBasic->GetModules();
-        for( sal_uInt16 j=0; j<pModules->Count(); j++ )
+        for( const auto& pModule: pBasic->GetModules() )
         {
-            const SbModule &rModule = dynamic_cast<const SbModule&>(*pModules->Get(j));
-
             OUString sLang(SVX_MACRO_LANGUAGE_STARBASIC);
             ScriptType eType = STARBASIC;
 
-            if( 0==i && 0==j )
+            if( bFirst )
             {
+                bFirst = false;
                 OutNewLine();
                 OStringBuffer sOut;
                 sOut.append('<').append(OOO_STRING_SVTOOLS_HTML_meta)
@@ -299,9 +297,9 @@ void SwHTMLWriter::OutBasic()
                    .WriteCharPtr( "\">" );
             }
 
-            const OUString& rModName = rModule.GetName();
+            const OUString& rModName = pModule->GetName();
             Strm().WriteCharPtr( SAL_NEWLINE_STRING );   // nicht einruecken!
-            HTMLOutFuncs::OutScript( Strm(), GetBaseURL(), rModule.GetSource(),
+            HTMLOutFuncs::OutScript( Strm(), GetBaseURL(), pModule->GetSource(),
                                      sLang, eType, aEmptyOUStr,
                                      &rLibName, &rModName,
                                      m_eDestEnc, &m_aNonConvertableCharacters );


More information about the Libreoffice-commits mailing list