[Libreoffice-commits] core.git: include/unotools unotools/source

Arnaud Versini (via logerrit) logerrit at kemper.freedesktop.org
Mon Sep 7 09:20:46 UTC 2020


 include/unotools/accessiblestatesethelper.hxx              |    4 
 unotools/source/accessibility/accessiblestatesethelper.cxx |  133 +++----------
 2 files changed, 38 insertions(+), 99 deletions(-)

New commits:
commit 54cbe9458033f50d9f608b1462d65e8514cbb636
Author:     Arnaud Versini <arnaud.versini at libreoffice.org>
AuthorDate: Sun Sep 6 19:01:24 2020 +0200
Commit:     Arnaud Versini <arnaud.versini at libreoffice.org>
CommitDate: Mon Sep 7 11:20:09 2020 +0200

    UNOTOOLS : simplify AccessibleStateSetHelper by not using an impl class
    
    Change-Id: Iae7a028d2845d8b0bef2aefdce2ae00fa7f5660f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102110
    Tested-by: Jenkins
    Reviewed-by: Arnaud Versini <arnaud.versini at libreoffice.org>

diff --git a/include/unotools/accessiblestatesethelper.hxx b/include/unotools/accessiblestatesethelper.hxx
index e8277f648903..140375503fb1 100644
--- a/include/unotools/accessiblestatesethelper.hxx
+++ b/include/unotools/accessiblestatesethelper.hxx
@@ -26,8 +26,6 @@
 #include <cppuhelper/implbase.hxx>
 #include <memory>
 
-class AccessibleStateSetHelperImpl;
-
 //= XAccessibleStateSet helper classes
 
 //... namespace utl .......................................................
@@ -134,7 +132,7 @@ private:
     /// Mutex guarding this object.
     ::osl::Mutex maMutex;
     /// The implementation of this helper interface.
-    std::unique_ptr<AccessibleStateSetHelperImpl>   mpHelperImpl;
+    sal_uInt64 maStates;
 };
 
 }
diff --git a/unotools/source/accessibility/accessiblestatesethelper.cxx b/unotools/source/accessibility/accessiblestatesethelper.cxx
index 9a180a4677ad..cec1f6bcd615 100644
--- a/unotools/source/accessibility/accessiblestatesethelper.cxx
+++ b/unotools/source/accessibility/accessiblestatesethelper.cxx
@@ -28,110 +28,32 @@ using namespace ::utl;
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::accessibility;
 
-class AccessibleStateSetHelperImpl
+namespace
 {
-public:
-    AccessibleStateSetHelperImpl();
-    AccessibleStateSetHelperImpl(const AccessibleStateSetHelperImpl& rImpl);
-
-    /// @throws uno::RuntimeException
-    bool IsEmpty () const;
-    /// @throws uno::RuntimeException
-    bool Contains (sal_Int16 aState) const;
-    /// @throws uno::RuntimeException
-    uno::Sequence<sal_Int16> GetStates() const;
-    /// @throws uno::RuntimeException
-    void AddState(sal_Int16 aState);
-    /// @throws uno::RuntimeException
-    void RemoveState(sal_Int16 aState);
-
-    inline void AddStates( const sal_Int64 _nStates );
-
-private:
-    sal_uInt64 maStates;
-};
-
-AccessibleStateSetHelperImpl::AccessibleStateSetHelperImpl()
-    : maStates(0)
-{
-}
-
-AccessibleStateSetHelperImpl::AccessibleStateSetHelperImpl(const AccessibleStateSetHelperImpl& rImpl)
-    : maStates(rImpl.maStates)
-{
-}
-
-inline bool AccessibleStateSetHelperImpl::IsEmpty () const
-{
-    return maStates == 0;
-}
-
-inline bool AccessibleStateSetHelperImpl::Contains (sal_Int16 aState) const
-{
-    DBG_ASSERT(aState < BITFIELDSIZE, "the statesset is too small");
-    sal_uInt64 aTempBitSet(1);
-    aTempBitSet <<= aState;
-    return ((aTempBitSet & maStates) != 0);
-}
-
-inline uno::Sequence<sal_Int16> AccessibleStateSetHelperImpl::GetStates() const
-{
-    uno::Sequence<sal_Int16> aRet(BITFIELDSIZE);
-    sal_Int16* pSeq = aRet.getArray();
-    sal_Int16 nStateCount(0);
-    for (sal_Int16 i = 0; i < BITFIELDSIZE; ++i)
-        if (Contains(i))
-        {
-            *pSeq = i;
-            ++pSeq;
-            ++nStateCount;
-        }
-    aRet.realloc(nStateCount);
-    return aRet;
-}
-
-inline void AccessibleStateSetHelperImpl::AddStates( const sal_Int64 _nStates )
-{
-    maStates |= _nStates;
+    bool lcl_contains(sal_uInt64 aStates, sal_uInt64 aState)
+    {
+        DBG_ASSERT(aState < BITFIELDSIZE, "the statesset is too small");
+        sal_uInt64 aTempBitSet(1);
+        aTempBitSet <<= aState;
+        return ((aTempBitSet & aStates) != 0);
+    }
 }
-
-inline void AccessibleStateSetHelperImpl::AddState(sal_Int16 aState)
-{
-    DBG_ASSERT(aState < BITFIELDSIZE, "the statesset is too small");
-    sal_uInt64 aTempBitSet(1);
-    aTempBitSet <<= aState;
-    maStates |= aTempBitSet;
-}
-
-inline void AccessibleStateSetHelperImpl::RemoveState(sal_Int16 aState)
-{
-    DBG_ASSERT(aState < BITFIELDSIZE, "the statesset is too small");
-    sal_uInt64 aTempBitSet(1);
-    aTempBitSet <<= aState;
-    aTempBitSet = ~aTempBitSet;
-    maStates &= aTempBitSet;
-}
-
 //=====  internal  ============================================================
 
 AccessibleStateSetHelper::AccessibleStateSetHelper ()
-    : mpHelperImpl(new AccessibleStateSetHelperImpl)
+    : maStates(0)
 {
 }
 
 AccessibleStateSetHelper::AccessibleStateSetHelper ( const sal_Int64 _nInitialStates )
-    : mpHelperImpl(new AccessibleStateSetHelperImpl)
+    : maStates(_nInitialStates)
 {
-    mpHelperImpl->AddStates( _nInitialStates );
 }
 
 AccessibleStateSetHelper::AccessibleStateSetHelper (const AccessibleStateSetHelper& rHelper)
-    : cppu::WeakImplHelper<XAccessibleStateSet>(rHelper)
+    : cppu::WeakImplHelper<XAccessibleStateSet>(rHelper),
+      maStates(rHelper.maStates)
 {
-    if (rHelper.mpHelperImpl)
-        mpHelperImpl.reset(new AccessibleStateSetHelperImpl(*rHelper.mpHelperImpl));
-    else
-        mpHelperImpl.reset(new AccessibleStateSetHelperImpl());
 }
 
 AccessibleStateSetHelper::~AccessibleStateSetHelper()
@@ -149,7 +71,7 @@ AccessibleStateSetHelper::~AccessibleStateSetHelper()
 sal_Bool SAL_CALL AccessibleStateSetHelper::isEmpty ()
 {
     osl::MutexGuard aGuard (maMutex);
-    return mpHelperImpl->IsEmpty();
+    return maStates == 0;
 }
 
     /** Checks if the given state is a member of the state set of this
@@ -166,7 +88,8 @@ sal_Bool SAL_CALL AccessibleStateSetHelper::isEmpty ()
 sal_Bool SAL_CALL AccessibleStateSetHelper::contains (sal_Int16 aState)
 {
     osl::MutexGuard aGuard (maMutex);
-    return mpHelperImpl->Contains(aState);
+
+    return lcl_contains(maStates, aState);
 }
 
     /** Checks if all of the given states are in this object's state
@@ -189,25 +112,43 @@ sal_Bool SAL_CALL AccessibleStateSetHelper::containsAll
 {
     osl::MutexGuard aGuard (maMutex);
     return std::all_of(rStateSet.begin(), rStateSet.end(),
-        [this](const sal_Int16 nState) { return mpHelperImpl->Contains(nState); });
+        [this](const sal_Int16 nState) { return lcl_contains(maStates, nState); });
 }
 
 uno::Sequence<sal_Int16> SAL_CALL AccessibleStateSetHelper::getStates()
 {
     osl::MutexGuard aGuard(maMutex);
-    return mpHelperImpl->GetStates();
+    uno::Sequence<sal_Int16> aRet(BITFIELDSIZE);
+    sal_Int16* pSeq = aRet.getArray();
+    sal_Int16 nStateCount(0);
+    for (sal_Int16 i = 0; i < BITFIELDSIZE; ++i)
+        if (lcl_contains(maStates, i))
+        {
+            *pSeq = i;
+            ++pSeq;
+            ++nStateCount;
+        }
+    aRet.realloc(nStateCount);
+    return aRet;
 }
 
 void AccessibleStateSetHelper::AddState(sal_Int16 aState)
 {
     osl::MutexGuard aGuard (maMutex);
-    mpHelperImpl->AddState(aState);
+    DBG_ASSERT(aState < BITFIELDSIZE, "the statesset is too small");
+    sal_uInt64 aTempBitSet(1);
+    aTempBitSet <<= aState;
+    maStates |= aTempBitSet;
 }
 
 void AccessibleStateSetHelper::RemoveState(sal_Int16 aState)
 {
     osl::MutexGuard aGuard (maMutex);
-    mpHelperImpl->RemoveState(aState);
+    DBG_ASSERT(aState < BITFIELDSIZE, "the statesset is too small");
+    sal_uInt64 aTempBitSet(1);
+    aTempBitSet <<= aState;
+    aTempBitSet = ~aTempBitSet;
+    maStates &= aTempBitSet;
 }
 
 //=====  XTypeProvider  =======================================================


More information about the Libreoffice-commits mailing list