[Libreoffice-commits] core.git: chart2/source comphelper/source include/comphelper svx/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Wed Aug 18 08:42:11 UTC 2021


 chart2/source/model/main/ChartModel.cxx             |    2 +-
 comphelper/source/container/interfacecontainer2.cxx |   14 ++++++++++++++
 include/comphelper/interfacecontainer2.hxx          |    2 ++
 svx/source/unodraw/unoshcol.cxx                     |    6 ++----
 4 files changed, 19 insertions(+), 5 deletions(-)

New commits:
commit 392f19c957b55de1ce834cb465f51f27c2c7cf60
Author:     Noel Grandin <noelgrandin at gmail.com>
AuthorDate: Tue Aug 17 18:48:06 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Wed Aug 18 10:41:34 2021 +0200

    improve SvxShapeCollection::getByIndex
    
    Change-Id: I4cca7c0b6344241256d038902069a20ece314358
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120618
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/chart2/source/model/main/ChartModel.cxx b/chart2/source/model/main/ChartModel.cxx
index ab846502f29f..9960f84c00b1 100644
--- a/chart2/source/model/main/ChartModel.cxx
+++ b/chart2/source/model/main/ChartModel.cxx
@@ -234,7 +234,7 @@ uno::Reference< frame::XController > ChartModel::impl_getCurrentController()
     // get the first controller of this model
     if( m_aControllers.getLength() )
     {
-        uno::Reference<uno::XInterface> xI = m_aControllers.getElements()[0];
+        uno::Reference<uno::XInterface> xI = m_aControllers.getInterface(0);
         return uno::Reference<frame::XController>( xI, uno::UNO_QUERY );
     }
 
diff --git a/comphelper/source/container/interfacecontainer2.cxx b/comphelper/source/container/interfacecontainer2.cxx
index 9ad26cc64cea..0881ccbe44cf 100644
--- a/comphelper/source/container/interfacecontainer2.cxx
+++ b/comphelper/source/container/interfacecontainer2.cxx
@@ -240,6 +240,20 @@ sal_Int32 OInterfaceContainerHelper2::removeInterface( const Reference<XInterfac
     return aData.pAsInterface ? 1 : 0;
 }
 
+Reference<XInterface> OInterfaceContainerHelper2::getInterface( sal_Int32 nIndex ) const
+{
+    MutexGuard aGuard( rMutex );
+
+    if( bIsList )
+        return (*aData.pAsVector)[nIndex];
+    else if( aData.pAsInterface )
+    {
+        if (nIndex == 0)
+            return aData.pAsInterface;
+    }
+    throw std::out_of_range("index out of range");
+}
+
 void OInterfaceContainerHelper2::disposeAndClear( const EventObject & rEvt )
 {
     ClearableMutexGuard aGuard( rMutex );
diff --git a/include/comphelper/interfacecontainer2.hxx b/include/comphelper/interfacecontainer2.hxx
index e001f56e6245..286a5f2cb876 100644
--- a/include/comphelper/interfacecontainer2.hxx
+++ b/include/comphelper/interfacecontainer2.hxx
@@ -171,6 +171,8 @@ public:
                 the new count of elements in the container
     */
     sal_Int32 removeInterface( const css::uno::Reference< css::uno::XInterface > & rxIFace );
+    /** Return an interface by index */
+    css::uno::Reference< css::uno::XInterface > getInterface(sal_Int32 nIndex) const;
     /**
       Call disposing on all object in the container that
       support XEventListener. Then clear the container.
diff --git a/svx/source/unodraw/unoshcol.cxx b/svx/source/unodraw/unoshcol.cxx
index 616f05151e8f..450de874753b 100644
--- a/svx/source/unodraw/unoshcol.cxx
+++ b/svx/source/unodraw/unoshcol.cxx
@@ -213,10 +213,8 @@ uno::Any SAL_CALL SvxShapeCollection::getByIndex( sal_Int32 Index )
     if( Index < 0 || Index >= getCount() )
         throw lang::IndexOutOfBoundsException();
 
-    std::vector< Reference< uno::XInterface> > aElements( maShapeContainer.getElements() );
-
-
-    return uno::makeAny( Reference< drawing::XShape>(static_cast< drawing::XShape* >( aElements[Index].get())) );
+    Reference< uno::XInterface> xInterface = maShapeContainer.getInterface(Index);
+    return uno::makeAny( Reference< drawing::XShape>(static_cast< drawing::XShape* >( xInterface.get())) );
 }
 
 // XElementAccess


More information about the Libreoffice-commits mailing list