i18npool/source/search/levdis.cxx  |   62 +++++--------------------------------
 i18npool/source/search/levdis.hxx  |    4 --
 sc/source/filter/html/htmlpars.cxx |   28 +---------------
 3 files changed, 11 insertions(+), 83 deletions(-)

New commits:
commit 995b3186fa2126d1b299052a90a75cf32d5bfa26
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Mon Apr 5 15:12:04 2021 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Mon Apr 5 15:16:23 2021 +0200

    Use std algorithms here
    
    Change-Id: Ib7bb92cca1f52067f9030b6c6fdc088409ca10ef
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113601
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/i18npool/source/search/levdis.cxx 
b/i18npool/source/search/levdis.cxx
index 5842abd1eef5..dd9f8fbf587a 100644
--- a/i18npool/source/search/levdis.cxx
+++ b/i18npool/source/search/levdis.cxx
@@ -56,6 +56,7 @@
 */
 
 #include <algorithm>
+#include <numeric>
 
 #include "levdis.hxx"
 
@@ -119,7 +120,7 @@ int WLevDistance::WLD( const sal_Unicode* cString, 
sal_Int32 nStringLen )
             nP = 0;     // a '?' could be any character.
         else
             // Minimum of replacement and deletion+insertion weighting
-            nP = Min3( nRepP0, nRepP0, nDelR0 + nInsQ0 );
+            nP = std::min({ nRepP0, nRepP0, nDelR0 + nInsQ0 });
         npDistance[0] = nInsQ0;     // start with simple insert
         npDistance[1] = nInsQ0;
         npDistance[2] = nInsQ0;
@@ -150,7 +151,7 @@ int WLevDistance::WLD( const sal_Unicode* cString, 
sal_Int32 nStringLen )
                 }
             }
         }
-        nSPMin = Min3( npDistance[0], npDistance[1], npDistance[2] );
+        nSPMin = std::min({ npDistance[0], npDistance[1], npDistance[2] });
     }
 
     // calculate distance matrix
@@ -203,7 +204,7 @@ int WLevDistance::WLD( const sal_Unicode* cString, 
sal_Int32 nStringLen )
             // WLD( X(i), Y(j) ) = min( WLD( X(i-1), Y(j-1) ) + p(i,j) ,
             //                          WLD( X(i)  , Y(j-1) ) + q      ,
             //                          WLD( X(i-1), Y(j)   ) + r      )
-            npDistance[i] = Min3( d1 + nPij, d2 + nQ, npDistance[i-1] + nR );
+            npDistance[i] = std::min({ d1 + nPij, d2 + nQ, npDistance[i-1] + 
nR });
             if ( npDistance[i] < nSPMin )
                 nSPMin = npDistance[i];
             if ( bSplitCount )
@@ -263,63 +264,27 @@ void WLevDistance::CalcLPQR( int nX, int nY, int nZ, bool 
bRelaxed )
     if ( nX < 0 ) nX = 0;       // only positive values
     if ( nY < 0 ) nY = 0;
     if ( nZ < 0 ) nZ = 0;
-    if (0 == Min3( nX, nY, nZ ))                // at least one 0
+    if (0 == std::min({ nX, nY, nZ })) // at least one 0
     {
         int nMid, nMax;
-        nMax = Max3( nX, nY, nZ );              // either 0 for three 0s or Max
+        nMax = std::max({ nX, nY, nZ }); // either 0 for three 0s or Max
         if ( 0 == (nMid = Mid3( nX, nY, nZ )) ) // even two 0
             nLimit = nMax;                      // either 0 or the only one >0
         else                                    // one is 0
-            nLimit = LCM( nMid, nMax );
+            nLimit = std::lcm( nMid, nMax );
     }
     else                                        // all three of them are not 0
-        nLimit = LCM( LCM( nX, nY ), nZ );
+        nLimit = std::lcm(std::lcm(nX, nY), nZ);
     nRepP0 = ( nX ? nLimit / nX : nLimit + 1 );
     nInsQ0 = ( nY ? nLimit / nY : nLimit + 1 );
     nDelR0 = ( nZ ? nLimit / nZ : nLimit + 1 );
     bSplitCount = bRelaxed;
 }
 
-// greatest common divisor according to Euklid (chaindivision)
-// special case: 0 plus anything produces 1
-int WLevDistance::GCD( int a, int b )
-{
-    if ( !a || !b )
-        return 1;
-    if ( a < 0 ) a = -a;
-    if ( b < 0 ) b = -b;
-    do
-    {
-        if ( a > b )
-            a -= int(a / b) * b;
-        else
-            b -= int(b / a) * a;
-    } while ( a && b );
-    return( a ? a : b);
-}
-
-// least common multiple : a * b / GCD(a,b)
-int WLevDistance::LCM( int a, int b )
-{
-    if ( a > b )    // decrease overflow chance
-        return( (a / GCD(a,b)) * b );
-    else
-        return( (b / GCD(a,b)) * a );
-}
-
-// Minimum of three values
-inline int WLevDistance::Min3( int x, int y, int z )
-{
-    if ( x < y )
-        return std::min(x, z);
-    else
-        return std::min(y, z);
-}
-
 // The value in the middle
 int WLevDistance::Mid3( int x, int y, int z )
 {
-    int min = Min3(x,y,z);
+    int min = std::min({ x, y, z });
     if ( x == min )
         return std::min(y, z);
     else if ( y == min )
@@ -328,15 +293,6 @@ int WLevDistance::Mid3( int x, int y, int z )
         return std::min(x, y);
 }
 
-// Maximum of three values
-int WLevDistance::Max3( int x, int y, int z )
-{
-    if ( x > y )
-        return std::max(x, z);
-    else
-        return std::max(y, z);
-}
-
 // initialize data from CTOR
 void WLevDistance::InitData( const sal_Unicode* cPattern )
 {
diff --git a/i18npool/source/search/levdis.hxx 
b/i18npool/source/search/levdis.hxx
index c789b7da8fb5..1dc570d39c21 100644
--- a/i18npool/source/search/levdis.hxx
+++ b/i18npool/source/search/levdis.hxx
@@ -147,11 +147,7 @@ class WLevDistance
     bool            bSplitCount;    ///< if TRUE, Rep/Ins/Del are counted 
separately
 
     void InitData( const sal_Unicode* cPattern );
-    static inline int Min3( int x, int y, int z ); ///< minimum value of 3 
values
     static int Mid3( int x, int y, int z );        ///< middle value of 3 
values
-    static int Max3( int x, int y, int z );        ///< maximum value of 3 
values
-    static int GCD( int a, int b );                ///< Greatest Common Divisor
-    static int LCM( int a, int b );                ///< Least Common Multiple
 
 public:
 
diff --git a/sc/source/filter/html/htmlpars.cxx 
b/sc/source/filter/html/htmlpars.cxx
index f922bb21b86d..394691b70cbe 100644
--- a/sc/source/filter/html/htmlpars.cxx
+++ b/sc/source/filter/html/htmlpars.cxx
@@ -61,6 +61,7 @@
 #include <com/sun/star/document/XDocumentProperties.hpp>
 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
 #include <com/sun/star/frame/XModel.hpp>
+#include <numeric>
 #include <utility>
 
 using ::editeng::SvxBorderLine;
@@ -880,31 +881,6 @@ IMPL_LINK( ScHTMLLayoutParser, HTMLImportHdl, 
HtmlImportInfo&, rInfo, void )
     }
 }
 
-// Greatest common divisor (Euclid)
-// Special case: 0 and something gives 1
-static SCROW lcl_GGT( SCROW a, SCROW b )
-{
-    if ( !a || !b )
-        return 1;
-    do
-    {
-        if ( a > b )
-            a -= SCROW(a / b) * b;
-        else
-            b -= SCROW(b / a) * a;
-    } while ( a && b );
-    return ((a != 0) ? a : b);
-}
-
-// Lowest common multiple: a * b / GCD(a,b)
-static SCROW lcl_KGV( SCROW a, SCROW b )
-{
-    if ( a > b )    // Make overflow even less likely
-        return (a / lcl_GGT(a,b)) * b;
-    else
-        return (b / lcl_GGT(a,b)) * a;
-}
-
 void ScHTMLLayoutParser::TableDataOn( HtmlImportInfo* pInfo )
 {
     if ( bInCell )
@@ -1158,7 +1134,7 @@ void ScHTMLLayoutParser::TableOff( const HtmlImportInfo* 
pInfo )
                 SCROW nRowsPerRow2; // Inner table
                 if ( nRowSpan > 1 )
                 {   // LCM to which we can map the inner and outer rows
-                    nRowKGV = lcl_KGV( nRowSpan, nRows );
+                    nRowKGV = std::lcm( nRowSpan, nRows );
                     nRowsPerRow1 = nRowKGV / nRowSpan;
                     nRowsPerRow2 = nRowKGV / nRows;
                 }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to