Author Topic: a fast look for in GenerateResultSet  (Read 11166 times)

Offline blueshake

  • Regular
  • ***
  • Posts: 459
a fast look for in GenerateResultSet
« on: November 18, 2009, 08:05:30 am »
hello:
I modify the codes in GenerateResultSet.It can make the search more faster.
how the GenerateResultSet did before:
1.according to the parent token(parentIdx) ,find out its all children ,match the children of the parent token with search text.
2.even worse when search in the global scope.it loop the whole tree to find out which one's scope is -1 and the do match.waste so much time here.

now:

1.search text in tokentree and match the m_ParentIndex with parentIdx.


not so good at English.so the explaination is not so good.so read the changed codes please. :wink:

Keep low and hear the sadness of little dog.
I fall in love with a girl,but I don't dare to tell her.What should I do?

Offline blueshake

  • Regular
  • ***
  • Posts: 459
Re: a fast look for in GenerateResultSet
« Reply #1 on: November 18, 2009, 08:09:02 am »
when I diff the changed files ,it always give such message.see the screen shot.


I just can not make a patch.Can anybody tell what is goinig on here?Thanks.
Keep low and hear the sadness of little dog.
I fall in love with a girl,but I don't dare to tell her.What should I do?

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6025
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: a fast look for in GenerateResultSet
« Reply #2 on: November 18, 2009, 08:16:50 am »
The GenerateResultSet function is really hard to understand and maintained. So, they must be refactored. I'm grad you have made such step! thanks.

Did you use the latest TortoiseSVN?

Or, you can follow the steps that morten told me

Re: New code completion remarks/issues
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 blueshake

  • Regular
  • ***
  • Posts: 459
Re: a fast look for in GenerateResultSet
« Reply #3 on: November 18, 2009, 08:23:49 am »
@ollydbg
still not work.I post the e-mail to you with attachment.maybe it work in your machine. :D
Keep low and hear the sadness of little dog.
I fall in love with a girl,but I don't dare to tell her.What should I do?

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6025
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: a fast look for in GenerateResultSet
« Reply #4 on: November 18, 2009, 08:41:20 am »
Done, In fact, it failed in my system too.
So, I opened these files in NotePad++, and "convert to UTF8 without BOM", then it works, here is the patch.

Code
Index: nativeparser.cpp
===================================================================
--- nativeparser.cpp (revision 5922)
+++ nativeparser.cpp (working copy)
@@ -2025,7 +2025,59 @@
     // done
     return result.size();
 }
+size_t NativeParser::GenerateResultSet(Parser* parser, const wxString& search, int parentIdx, TokenIdxSet& result, bool caseSens, bool isPrefix, short int kindMask)
+{
+    if (!parser)
+        return 0;
+    if (search.IsEmpty())
+    {
+        Token* parent = parser->GetTokens()->at(parentIdx);
+        if (parent)
+        {
+            for (TokenIdxSet::iterator it = parent->m_Children.begin(); it != parent->m_Children.end(); ++it)
+            {
+                Token* token = parser->GetTokens()->at(*it);
+                if (token)
+                    result.insert(*it);
+            }
+            for (TokenIdxSet::iterator it = parent->m_Ancestors.begin(); it != parent->m_Ancestors.end(); ++it)
+            {
+                Token* ancestor = parser->GetTokens()->at(*it);
+                if (!ancestor)
+                    continue;
+                for (TokenIdxSet::iterator it2 = ancestor->m_Children.begin(); it2 != ancestor->m_Children.end(); ++it2)
+                {
+                    Token* token = parser->GetTokens()->at(*it2);
+                    if (token)
+                    {
+                        result.insert(*it2);
+                        if (token->m_TokenKind == tkEnum) // check enumerators for match too
+                        {
+                            for(TokenIdxSet::iterator it3 = token->m_Children.begin(); it3 != token->m_Children.end(); ++it3)
+                            result.insert(*it3);
+                        }
+                    }
+            }
+        }
 
+        }
+    }
+    else
+    {
+        TokenIdxSet tempResult;
+        if (parser->FindMatches(search, tempResult, caseSens, isPrefix))
+        {
+            for (TokenIdxSet::iterator it = tempResult.begin(); it != tempResult.end(); ++it)
+            {
+                Token* token = parser->GetTokens()->at(*it);
+                if (token && (token->m_ParentIndex ==parentIdx))
+                    result.insert(*it);
+
+            }
+        }
+    }
+    return result.size();
+}
 // Decides if the token belongs to its parent or one of its ancestors
 bool NativeParser::BelongsToParentOrItsAncestors(TokensTree* tree, Token* token, int parentIdx, bool use_inheritance)
 {
Index: nativeparser.h
===================================================================
--- nativeparser.h (revision 5922)
+++ nativeparser.h (working copy)
@@ -104,7 +104,7 @@
         size_t BreakUpComponents(Parser* parser, const wxString& actual, std::queue<ParserComponent>& components);
         bool BelongsToParentOrItsAncestors(TokensTree* tree, Token* token, int parentIdx, bool use_inheritance = true);
         size_t GenerateResultSet(TokensTree* tree, const wxString& search, int parentIdx, TokenIdxSet& result, bool caseSens = true, bool isPrefix = false, short int kindMask = 0xFFFF);
-
+        size_t GenerateResultSet(Parser* parser, const wxString& search, int parentIdx, TokenIdxSet& result, bool caseSens = true, bool isPrefix = false, short int kindMask = 0xFFFF);
         bool LastAISearchWasGlobal() const { return m_LastAISearchWasGlobal; }
         const wxString& LastAIGlobalSearch() const { return m_LastAIGlobalSearch; }
 
Index: parser/parser.cpp
===================================================================
--- parser/parser.cpp (revision 5922)
+++ parser/parser.cpp (working copy)
@@ -424,7 +424,24 @@
     }
     return result.size();
 }
+size_t Parser::FindMatches(const wxString& s,TokenIdxSet& result,bool caseSensitive,bool is_prefix)
+{
+    result.clear();
+    TokenIdxSet tmpresult;
+    wxCriticalSectionLocker lock(s_MutexProtection);
+    if(!m_pTokens->FindMatches(s,tmpresult,caseSensitive,is_prefix))
+        return 0;
 
+    TokenIdxSet::iterator it;
+    for(it = tmpresult.begin();it!=tmpresult.end();++it)
+    {
+        Token* token = m_pTokens->at(*it);
+        if(token)
+        //result.push_back(token);
+        result.insert(*it);
+    }
+    return result.size();
+}
 void Parser::LinkInheritance(bool tempsOnly)
 {
     wxCriticalSectionLocker lock(s_MutexProtection);
Index: parser/parser.h
===================================================================
--- parser/parser.h (revision 5922)
+++ parser/parser.h (working copy)
@@ -147,7 +147,7 @@
         Token* FindTokenByName(const wxString& name, bool globalsOnly = true, short int kindMask = 0xFFFF) const;
         Token* FindChildTokenByName(Token* parent, const wxString& name, bool useInheritance = false, short int kindMask = 0xFFFF) const;
         size_t FindMatches(const wxString& s,TokenList& result,bool caseSensitive = true,bool is_prefix = true);
-
+        size_t FindMatches(const wxString& s,TokenIdxSet& result,bool caseSensitive = true,bool is_prefix = true);
         ParserOptions& Options(){ return m_Options; }
         BrowserOptions& ClassBrowserOptions(){ return m_BrowserOptions; }
 

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 blueshake

  • Regular
  • ***
  • Posts: 459
Re: a fast look for in GenerateResultSet
« Reply #5 on: November 18, 2009, 10:00:25 am »
Quote
Done, In fact, it failed in my system too.
So, I opened these files in NotePad++, and "convert to UTF8 without BOM", then it works, here is the patch.
yeah,it work,thank you for your help.comments are welcome.
Keep low and hear the sadness of little dog.
I fall in love with a girl,but I don't dare to tell her.What should I do?