[Libreoffice-commits] core.git: sc/source

Mike Kaganski (via logerrit) logerrit at kemper.freedesktop.org
Thu May 2 14:21:35 UTC 2019


 sc/source/ui/unoobj/dapiuno.cxx |   78 ++++++++++++----------------------------
 1 file changed, 24 insertions(+), 54 deletions(-)

New commits:
commit 96ab20756316b25b7f2343a15596bc5114ea5a68
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Thu May 2 13:26:52 2019 +0200
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Thu May 2 16:20:38 2019 +0200

    Deduplicate some code
    
    Change-Id: Ia57947276a5d561f57bb3fe677451b77a80a1009
    Reviewed-on: https://gerrit.libreoffice.org/71671
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/sc/source/ui/unoobj/dapiuno.cxx b/sc/source/ui/unoobj/dapiuno.cxx
index 0f3fa929ef4a..44fbc9dcac93 100644
--- a/sc/source/ui/unoobj/dapiuno.cxx
+++ b/sc/source/ui/unoobj/dapiuno.cxx
@@ -1496,28 +1496,17 @@ static sal_Int32 lcl_GetFieldCount( const Reference<XDimensionsSupplier>& rSourc
     Reference<XNameAccess> xDimsName(rSource->getDimensions());
     Reference<XIndexAccess> xIntDims(new ScNameToIndexAccess( xDimsName ));
     sal_Int32 nIntCount = xIntDims->getCount();
-    if (rOrient.hasValue())
+    for (sal_Int32 i = 0; i < nIntCount; ++i)
     {
-        // all fields of the specified orientation, including duplicated
-        Reference<XPropertySet> xDim;
-        for (sal_Int32 i = 0; i < nIntCount; ++i)
-        {
-            xDim.set(xIntDims->getByIndex(i), UNO_QUERY);
-            if (xDim.is() && (xDim->getPropertyValue(SC_UNO_DP_ORIENTATION) == rOrient))
-                ++nRet;
-        }
-    }
-    else
-    {
-        // count all non-duplicated fields
-
-        Reference<XPropertySet> xDim;
-        for (sal_Int32 i = 0; i < nIntCount; ++i)
-        {
-            xDim.set(xIntDims->getByIndex(i), UNO_QUERY);
-            if ( xDim.is() && !lcl_IsDuplicated( xDim ) )
-                ++nRet;
-        }
+        Reference<XPropertySet> xDim(xIntDims->getByIndex(i), UNO_QUERY);
+        const bool bMatch = xDim
+                            && (rOrient.hasValue()
+                                    // all fields of the specified orientation, including duplicated
+                                    ? (xDim->getPropertyValue(SC_UNO_DP_ORIENTATION) == rOrient)
+                                    // count all non-duplicated fields
+                                    : !lcl_IsDuplicated(xDim));
+        if (bMatch)
+            ++nRet;
     }
 
     return nRet;
@@ -1537,42 +1526,23 @@ static bool lcl_GetFieldDataByIndex( const Reference<XDimensionsSupplier>& rSour
     Reference<XIndexAccess> xIntDims(new ScNameToIndexAccess( xDimsName ));
     sal_Int32 nIntCount = xIntDims->getCount();
     Reference<XPropertySet> xDim;
-    if (rOrient.hasValue())
-    {
-        sal_Int32 i = 0;
-        while (i < nIntCount && !bOk)
+    for (sal_Int32 i = 0; i < nIntCount; ++i)
+    {
+        xDim.set(xIntDims->getByIndex(i), UNO_QUERY);
+        const bool bMatch = xDim
+                            && (rOrient.hasValue()
+                                    ? (xDim->getPropertyValue(SC_UNO_DP_ORIENTATION) == rOrient)
+                                    : !lcl_IsDuplicated(xDim));
+        if (bMatch)
         {
-            xDim.set(xIntDims->getByIndex(i), UNO_QUERY);
-            if (xDim.is() && (xDim->getPropertyValue(SC_UNO_DP_ORIENTATION) == rOrient))
+            if (nPos == nIndex)
             {
-                if (nPos == nIndex)
-                {
-                    bOk = true;
-                    nDimIndex = i;
-                }
-                else
-                    ++nPos;
+                bOk = true;
+                nDimIndex = i;
+                break;
             }
-            ++i;
-        }
-    }
-    else
-    {
-        sal_Int32 i = 0;
-        while (i < nIntCount && !bOk)
-        {
-            xDim.set(xIntDims->getByIndex(i), UNO_QUERY);
-            if ( xDim.is() && !lcl_IsDuplicated( xDim ) )
-            {
-                if (nPos == nIndex)
-                {
-                    bOk = true;
-                    nDimIndex = i;
-                }
-                else
-                    ++nPos;
-            }
-            ++i;
+            else
+                ++nPos;
         }
     }
 


More information about the Libreoffice-commits mailing list