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

New commits:
commit fd66dc25f5c381e0727013a700f2b08459372aec
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Thu Jan 26 22:03:42 2023 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Fri Jan 27 09:00:58 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>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146248

diff --git a/basic/source/inc/runtime.hxx b/basic/source/inc/runtime.hxx
index 65be051e704f..2ab1ffaf3705 100644
--- a/basic/source/inc/runtime.hxx
+++ b/basic/source/inc/runtime.hxx
@@ -248,7 +248,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 7eb0d022e8ee..18118da3c1e7 100644
--- a/basic/source/runtime/runtime.cxx
+++ b/basic/source/runtime/runtime.cxx
@@ -570,7 +570,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 ), 
mpExtCaller(nullptr), m_nLastTime(0)
+           pMod( pm ), pMeth( pe ), pImg( pMod->pImage ), mpExtCaller(nullptr)
 {
     nFlags    = pe ? pe->GetDebugFlags() : BasicDebugFlags::NONE;
     pIosys    = pInst->GetIoSystem();
@@ -763,23 +763,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