basic/source/inc/runtime.hxx     |    1 -
 basic/source/runtime/runtime.cxx |   11 +++++++----
 2 files changed, 7 insertions(+), 5 deletions(-)

New commits:
commit 358f21e0c2de2067c14c54ce41954954508d3550
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Thu Jan 26 22:03:42 2023 +0300
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Wed Feb 1 12:12:18 2023 +0000

    tdf#153235: Optimize Application::Reschedule calls in SbiRuntime::Step
    
    Setup the "last reschedule time" counter at the first pass,
    to avoid useless immediate reschedule.
    Update the counter when running "when blocked" reschedules.
    
    This seems to avoid the problem with the bugdoc.
    
    Change-Id: Ib5958a1a2b048f5ec654c69ee9e977e8a26de6f5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146215
    Tested-by: Mike Kaganski <mike.kagan...@collabora.com>
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146246
    Tested-by: Jenkins

diff --git a/basic/source/inc/runtime.hxx b/basic/source/inc/runtime.hxx
index d0922e6a0e0a..a6e12b50106d 100644
--- a/basic/source/inc/runtime.hxx
+++ b/basic/source/inc/runtime.hxx
@@ -250,7 +250,6 @@ class SbiRuntime
     BasicDebugFlags    nFlags;           // Debugging-Flags
     ErrCode            nError;
     sal_uInt16         nOps;             // opcode counter
-    sal_uInt32         m_nLastTime;
 
     std::vector<SbxVariableRef>  aRefSaved; // #74254 save temporary references
     std::vector<SbiGosub>   pGosubStk;      // GOSUB stack
diff --git a/basic/source/runtime/runtime.cxx b/basic/source/runtime/runtime.cxx
index 6a15cb1606e6..23e65805240c 100644
--- a/basic/source/runtime/runtime.cxx
+++ b/basic/source/runtime/runtime.cxx
@@ -599,7 +599,7 @@ SbMethod* SbiInstance::GetCaller( sal_uInt16 nLevel )
 
 SbiRuntime::SbiRuntime( SbModule* pm, SbMethod* pe, sal_uInt32 nStart )
          : rBasic( *static_cast<StarBASIC*>(pm->pParent) ), pInst( 
GetSbData()->pInst ),
-           pMod( pm ), pMeth( pe ), pImg( pMod->pImage.get() ), 
mpExtCaller(nullptr), m_nLastTime(0)
+           pMod( pm ), pMeth( pe ), pImg( pMod->pImage.get() ), 
mpExtCaller(nullptr)
 {
     nFlags    = pe ? pe->GetDebugFlags() : BasicDebugFlags::NONE;
     pIosys    = pInst->GetIoSystem();
@@ -792,23 +792,26 @@ bool SbiRuntime::Step()
 {
     if( bRun )
     {
+        static sal_uInt32 nLastTime = osl_getGlobalTimer();
+
         // in any case check casually!
         if( !( ++nOps & 0xF ) && pInst->IsReschedule() )
         {
             sal_uInt32 nTime = osl_getGlobalTimer();
-            if (nTime - m_nLastTime > 5 ) // 20 ms
+            if (nTime - nLastTime > 5) // 20 ms
             {
+                nLastTime = nTime;
                 Application::Reschedule();
-                m_nLastTime = nTime;
             }
         }
 
         // #i48868 blocked by next call level?
         while( bBlocked )
         {
-            if( pInst->IsReschedule() )
+            if( pInst->IsReschedule() ) // And what if not? Busy loop?
             {
                 Application::Reschedule();
+                nLastTime = osl_getGlobalTimer();
             }
         }
 

Reply via email to