Author Topic: Commit rev 6058 question  (Read 10299 times)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Commit rev 6058 question
« on: November 13, 2013, 06:29:42 am »
When discuss this patch:
CodeCompletion: fixes UnnamedStruct in the classBrowser, see the commens there, the main issue is:

I see that in rev =/@6057&compare[]=/@6058]WebSVN - codeblocks - Path Comparison - / Rev 6057 and / Rev 6058

Code
-int TokensTree::AddToken(Token* newToken,int forceidx)
+int TokensTree::AddToken(Token* newToken, int fileIndex)
 {
     if (!newToken)
         return -1;
 
     const wxString & name = newToken->m_Name;
 
-    static TokenIdxSet tmp_tokens = TokenIdxSet();
-    // tmp_tokens.clear();
+    static TokenIdxSet tmpTokens = TokenIdxSet();
 
     // Insert the token's name and the token in the (inserted?) list
-    size_t idx2 = m_Tree.AddItem(name,tmp_tokens,false);
-    TokenIdxSet& curlist = m_Tree.GetItemAtPos(idx2);
+    size_t idx = m_Tree.AddItem(name, tmpTokens);
+    TokenIdxSet& curList = m_Tree.GetItemAtPos(idx);
+
+    int newItem = AddTokenToList(newToken, fileIndex);
+    curList.insert(newItem);
 
-    int newitem = AddTokenToList(newToken,forceidx);
-    curlist.insert(newitem);
-    m_FilesMap[newToken->m_FileIdx].insert(newitem);
+    size_t fileIdx = (fileIndex<0) ? newToken->m_FileIdx : (size_t)fileIndex;
+    m_FilesMap[fileIdx].insert(newItem);
 
     // Add Token (if applicable) to the namespaces indexes
     if (newToken->m_ParentIndex < 0)
     {
         newToken->m_ParentIndex = -1;
-        m_GlobalNameSpace.insert(newitem);
+        m_GlobalNameSpace.insert(newItem);
         if (newToken->m_TokenKind == tkNamespace)
-            m_TopNameSpaces.insert(newitem);
+            m_TopNameSpaces.insert(newItem);
     }
 
     // All done!
-    return newitem;
+    return newItem;
 }

The function parameter is "token index" as I see, but it was changed to "file index"?????

EDIT:
old:
Code
int newitem = AddTokenToList(newToken,forceidx);

new:
Code
int newItem = AddTokenToList(newToken, fileIndex);

I see that AddTokenToList() function's second parameter is the token index not file index.

« Last Edit: November 13, 2013, 07:12:14 am by ollydbg »
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 ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Commit rev 6058 question
« Reply #1 on: November 13, 2013, 07:48:56 am »
The lucky thing is:
Code
size_t fileIdx = (fileIndex<0) ? newToken->m_FileIdx : (size_t)fileIndex;
Here, fileIndex is always < 0 (Unless we construct the Token tree from the cache)
So, the later code always works OK, because fileIdx is always newToken->m_FileIdx.
Code
m_FilesMap[fileIdx].insert(newItem);
« Last Edit: November 13, 2013, 07:56:22 am by ollydbg »
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 ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Commit rev 6058 question
« Reply #2 on: November 13, 2013, 08:50:39 am »
Ok, a patch to fix this issue (include the CodeCompletion: fixes UnnamedStruct in the classBrowser)

EDIT: update to version 2 of the patch
« Last Edit: November 13, 2013, 03:46:21 pm by ollydbg »
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 ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Commit rev 6058 question
« Reply #3 on: November 17, 2013, 03:53:33 pm »
Version 3 of the patch.
See attachment.
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.