Author Topic: question about m_NeedsBatchColour variable in CC  (Read 10525 times)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6025
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
question about m_NeedsBatchColour variable in CC
« on: August 19, 2015, 06:20:34 am »
When the parsing for a project is done, we can make a simple syntax highlight on the editors.
The variable m_NeedsBatchColour is used to record that after the ParserEnd event, all the opened editors should be highlighted. Do we really need that, because I see
Code
void CodeCompletion::OnEditorActivatedTimer(cb_unused wxTimerEvent& event)
{
    ...
    UpdateEditorSyntax();
}


So, generally, I think we don't need to refresh the syntax highlight after the ParserEnd event. Here is the patch:

Code
 src/plugins/codecompletion/codecompletion.cpp | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/src/plugins/codecompletion/codecompletion.cpp b/src/plugins/codecompletion/codecompletion.cpp
index 9666a3f..9d8ab6e 100644
--- a/src/plugins/codecompletion/codecompletion.cpp
+++ b/src/plugins/codecompletion/codecompletion.cpp
@@ -2568,17 +2568,11 @@ void CodeCompletion::OnParserEnd(wxCommandEvent& event)
         m_ToolbarNeedReparse = true;
         TRACE(_T("CodeCompletion::OnParserEnd: Starting m_TimerToolbar."));
         m_TimerToolbar.Start(TOOLBAR_REFRESH_DELAY, wxTIMER_ONE_SHOT);
-    }
-
-    if (m_NeedsBatchColour)
-    {
-        for (int edIdx = edMan->GetEditorsCount() - 1; edIdx >= 0; --edIdx)
+        if (m_NeedsBatchColour)
         {
-            editor = edMan->GetBuiltinEditor(edIdx);
-            if (editor)
-                UpdateEditorSyntax(editor);
+            UpdateEditorSyntax(editor);
+            m_NeedsBatchColour = false;
         }
-        m_NeedsBatchColour = false;
     }
 
     event.Skip();

What do you think?
Thanks
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9702
Re: question about m_NeedsBatchColour variable in CC
« Reply #1 on: August 19, 2015, 08:04:27 am »
What do you think?
It might cause a slight delay which can be visible. Do you experience such after the patch?
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6025
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: question about m_NeedsBatchColour variable in CC
« Reply #2 on: August 19, 2015, 02:41:51 pm »
What do you think?
It might cause a slight delay which can be visible. Do you experience such after the patch?

Yes, I can see the visible delay. For example, a project have four files: a.cpp, b.cpp, c.cpp, d.cpp, when project loaded, a.cpp and b.cpp will be opened automatically, suppose b.cpp is the active editor.

The old code is that when finish parsing the project, the opened editors(a.cpp and b.cpp) will be colourised. When I switch to a.cpp, the a.cpp will colourised again, but you don't notice the visible delay, because a.cpp is already colourised. While, if you double click on the c.cpp in the project manager tree, c.cpp will opened and activated, and you notice the visible delay on c.cpp.

After my patch, after parsing the project, only b.cpp(the active editor) will be colourised, when you switch to a.cpp or open c.cpp, you will notice the visual delay.

BTW: I notice that if I double click on the c.cpp in the project file tree, I will receive many editor active events, see below:
Code
20:40:00,156  =>  cbEVT_EDITOR_DEACTIVATED
20:40:00,156  =>  cbEVT_EDITOR_SWITCHED
20:40:00,156  =>  cbEVT_EDITOR_ACTIVATED
Mozilla universal detection engine detected 'Pure *ASCII*'.
Final encoding detected: Windows Chinese Simplified (CP 936) (ID: 28)
Conversion succeeded using wxCSConv (buffer size = 143129, converted size = 143130.
20:40:00,218  =>  cbEVT_EDITOR_OPEN
20:40:00,250  =>  cbEVT_EDITOR_SWITCHED
20:40:00,250  =>  cbEVT_EDITOR_ACTIVATED
20:40:00,250  =>  cbEVT_EDITOR_SWITCHED
20:40:00,250  =>  cbEVT_EDITOR_ACTIVATED
20:40:00,265  =>  cbEVT_EDITOR_UPDATE_UI
NativeParser::GetAllPathsByFilename(): Traversing 'F:\cb_sf_git\trunk\src\plugins\codecompletion\parser' for: parserthread.*
NativeParser::GetAllPathsByFilename(): Found 2 files:
- F:\cb_sf_git\trunk\src\plugins\codecompletion\parser\parserthread.cpp
- F:\cb_sf_git\trunk\src\plugins\codecompletion\parser\parserthread.h
ClassBrowser::OnThreadEvent(): Updating class browser...
20:40:00,687  =>  cbEVT_EDITOR_UPDATE_UI
ClassBrowser::OnThreadEvent(): Class browser updated.
This is reported by Jens' event monitor plugin. when a new file "parserthread.cpp" is opened by double click on the project manager tree. Not sure why, but I think that's one reason why we need an "editor active timer delay", thus we can only handle the last activated editor event.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.