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

Winfried Donkers winfrieddonkers at libreoffice.org
Wed Apr 9 08:54:51 PDT 2014


 sc/source/core/inc/interpre.hxx  |    8 ++++
 sc/source/core/tool/interpr2.cxx |   64 +++++++++++++++++----------------------
 2 files changed, 35 insertions(+), 37 deletions(-)

New commits:
commit 8facc14e88251d9356995d9e8e213084212e88a5
Author: Winfried Donkers <winfrieddonkers at libreoffice.org>
Date:   Fri Apr 4 13:56:07 2014 +0200

    fdo#73147 improve function code for speed
    
    Change-Id: I8862c1aaf245796a475ce52bec6c8e9a32862bbd
    Reviewed-on: https://gerrit.libreoffice.org/8841
    Reviewed-by: Eike Rathke <erack at redhat.com>
    Tested-by: Eike Rathke <erack at redhat.com>

diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx
index e0e36ed..7f2eb64 100644
--- a/sc/source/core/inc/interpre.hxx
+++ b/sc/source/core/inc/interpre.hxx
@@ -590,8 +590,9 @@ void ScGetDay();
 void ScGetDayOfWeek();
 void ScGetWeekOfYear();
 void ScEasterSunday();
-sal_uInt16 GetWeekendAndHolidayMasks( const sal_uInt8 nParamCount, const Date& rNullDate,
+sal_uInt16 GetWeekendAndHolidayMasks( const sal_uInt8 nParamCount, const sal_uInt32 nNullDate,
         ::std::vector<double>& rSortArray, OUString& rWeekendDays, bool bWeekendMask[ 7 ] );
+inline sal_Int16 GetDayOfWeek( sal_Int32 n );
 void ScNetWorkdays_MS();
 void ScWorkday_MS();
 void ScGetHour();
@@ -946,6 +947,11 @@ inline double ScInterpreter::div( const double& fNumerator, const double& fDenom
         CreateDoubleError( errDivisionByZero);
 }
 
+inline sal_Int16 ScInterpreter::GetDayOfWeek( sal_Int32 n )
+{   // monday = 0, ..., sunday = 6
+    return static_cast< sal_Int16 >( ( n - 1 ) % 7 );
+}
+
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx
index 85707a2..7e89a4f 100644
--- a/sc/source/core/tool/interpr2.cxx
+++ b/sc/source/core/tool/interpr2.cxx
@@ -249,7 +249,7 @@ void ScInterpreter::ScEasterSunday()
 }
 
 sal_uInt16 ScInterpreter::GetWeekendAndHolidayMasks(
-    const sal_uInt8 nParamCount, const Date& rNullDate, vector< double >& rSortArray,
+    const sal_uInt8 nParamCount, const sal_uInt32 nNullDate, vector< double >& rSortArray,
     OUString& rWeekendDays, bool bWeekendMask[ 7 ] )
 {
     sal_uInt16 nErr = 0;
@@ -258,11 +258,7 @@ sal_uInt16 ScInterpreter::GetWeekendAndHolidayMasks(
         GetSortArray( 1, rSortArray );
         size_t nMax = rSortArray.size();
         for ( size_t i = 0; i < nMax; i++ )
-        {
-            Date aTempDate( rNullDate );
-            aTempDate += ::rtl::math::approxFloor( rSortArray.at( i ) );
-            rSortArray.at( i ) = aTempDate.GetDate();
-        }
+            rSortArray.at( i ) = ::rtl::math::approxFloor( rSortArray.at( i ) ) + nNullDate;
     }
 
     if ( nParamCount >= 3 )
@@ -342,39 +338,36 @@ void ScInterpreter::ScNetWorkdays_MS()
         bool bWeekendMask[ 7 ];
         OUString aWeekendDays;
         Date aNullDate = *( pFormatter->GetNullDate() );
-        sal_uInt16 nErr = GetWeekendAndHolidayMasks( nParamCount, aNullDate,
+        sal_uInt32 nNullDate = Date::DateToDays( aNullDate.GetDay(), aNullDate.GetMonth(), aNullDate.GetYear() );
+        sal_uInt16 nErr = GetWeekendAndHolidayMasks( nParamCount, nNullDate,
                             nSortArray , aWeekendDays, bWeekendMask );
         if ( nErr )
             PushError( nErr );
         else
         {
-            double nDate2 = GetDouble();
-            double nDate1 = GetDouble();
-            Date aDate2( aNullDate );
-            aDate2 += ( long )::rtl::math::approxFloor( nDate2 );
-            Date aDate1( aNullDate );
-            aDate1 += ( long )::rtl::math::approxFloor( nDate1 );
+            sal_uInt32 nDate2 = ( sal_uInt32 )::rtl::math::approxFloor( GetDouble() ) + nNullDate;
+            sal_uInt32 nDate1 = ( sal_uInt32 )::rtl::math::approxFloor( GetDouble() ) + nNullDate;
 
             sal_Int32 nCnt = 0;
             size_t nRef = 0;
-            bool bReverse = ( aDate1 > aDate2 );
+            bool bReverse = ( nDate1 > nDate2 );
             if ( bReverse )
             {
-                Date aTempDate( aDate1 );
-                aDate1 = aDate2;
-                aDate2 = aTempDate;
+                sal_uInt32 nTemp = nDate1;
+                nDate1 = nDate2;
+                nDate2 = nTemp;
             }
             size_t nMax = nSortArray.size();
-            while ( aDate1 <= aDate2 )
+            while ( nDate1 <= nDate2 )
             {
-                if ( !bWeekendMask[ aDate1.GetDayOfWeek() ] )
+                if ( !bWeekendMask[ GetDayOfWeek( nDate1 ) ] )
                 {
-                    while ( nRef < nMax && nSortArray.at( nRef ) < aDate1.GetDate() )
+                    while ( nRef < nMax && nSortArray.at( nRef ) < nDate1 )
                         nRef++;
-                    if ( !( nRef < nMax && nSortArray.at( nRef ) == aDate1.GetDate() ) )
+                    if ( !( nRef < nMax && nSortArray.at( nRef ) == nDate1 ) )
                         nCnt++;
                 }
-                ++aDate1;
+                ++nDate1;
             }
             PushDouble( ( double ) ( bReverse ? -nCnt : nCnt ) );
         }
@@ -391,19 +384,18 @@ void ScInterpreter::ScWorkday_MS()
         bool bWeekendMask[ 7 ];
         OUString aWeekendDays;
         Date aNullDate = *( pFormatter->GetNullDate() );
-        sal_uInt16 nErr = GetWeekendAndHolidayMasks( nParamCount, aNullDate,
+        sal_uInt32 nNullDate = Date::DateToDays( aNullDate.GetDay(), aNullDate.GetMonth(), aNullDate.GetYear() );
+        sal_uInt16 nErr = GetWeekendAndHolidayMasks( nParamCount, nNullDate,
                             nSortArray , aWeekendDays, bWeekendMask );
         if ( nErr )
             PushError( nErr );
         else
         {
             sal_Int32 nDays = ::rtl::math::approxFloor( GetDouble() );
-            double nDate = GetDouble();
-            Date aDate( aNullDate );
-            aDate += ( long )::rtl::math::approxFloor( nDate );
+            sal_uInt32 nDate = ( sal_uInt32 )::rtl::math::approxFloor( GetDouble() ) + nNullDate;
 
             if ( !nDays )
-                PushDouble( ( double ) ( aDate - aNullDate ) );
+                PushDouble( ( double ) ( nDate - nNullDate ) );
             else
             {
                 size_t nMax = nSortArray.size();
@@ -412,14 +404,14 @@ void ScInterpreter::ScWorkday_MS()
                     size_t nRef = 0;
                     while ( nDays )
                     {
-                        while ( nRef < nMax && nSortArray.at( nRef ) < aDate.GetDate() )
+                        while ( nRef < nMax && nSortArray.at( nRef ) < nDate )
                             nRef++;
-                        if ( !( nRef < nMax && nSortArray.at( nRef ) == aDate.GetDate() ) || nRef >= nMax )
+                        if ( !( nRef < nMax && nSortArray.at( nRef ) == nDate ) || nRef >= nMax )
                              nDays--;
 
                         do
-                            ++aDate;
-                        while ( bWeekendMask[ aDate.GetDayOfWeek() ] ); //jump over weekend day(s)
+                            ++nDate;
+                        while ( bWeekendMask[ GetDayOfWeek( nDate ) ] ); //jump over weekend day(s)
                     }
                 }
                 else
@@ -427,17 +419,17 @@ void ScInterpreter::ScWorkday_MS()
                     sal_Int16 nRef = nMax - 1;
                     while ( nDays )
                     {
-                        while ( nRef >= 0 && nSortArray.at( nRef ) > aDate.GetDate() )
+                        while ( nRef >= 0 && nSortArray.at( nRef ) > nDate )
                             nRef--;
-                        if ( !( nRef >= 0 && nSortArray.at( nRef ) == aDate.GetDate() ) || nRef < 0 )
+                        if ( !( nRef >= 0 && nSortArray.at( nRef ) == nDate ) || nRef < 0 )
                              nDays++;
 
                         do
-                          --aDate;
-                        while ( bWeekendMask[ aDate.GetDayOfWeek() ] ); //jump over weekend day(s)
+                          --nDate;
+                        while ( bWeekendMask[ GetDayOfWeek( nDate ) ] ); //jump over weekend day(s)
                     }
                 }
-                PushDouble( ( double ) ( aDate - aNullDate ) );
+                PushDouble( ( double ) ( nDate - nNullDate ) );
             }
         }
     }


More information about the Libreoffice-commits mailing list