[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdevelop/languages/cpp/cppduchain
From:       David Nolden <david.nolden.kde () art-master ! de>
Date:       2008-02-14 13:20:11
Message-ID: 1202995211.914874.20023.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 774953 by zwabel:

Return the result of set_contains in Set::contains().
Make set_contains iterative instead of recursive, which should make it a lot faster.



 M  +14 -8     setrepository.cpp  


--- trunk/KDE/kdevelop/languages/cpp/cppduchain/setrepository.cpp #774952:774953
@@ -675,15 +675,22 @@
   return 0;
 }
 
-bool set_contains(SetNode* first, Index index)
+bool set_contains(SetNode* node, Index index)
 {
-  if(first->start > index || first->end <= index)
-    return false;
+  while(true) {
+    if(node->start > index || node->end <= index)
+      return false;
 
-  if(first->contiguous || !first->left || !first->right)
-    return true;
+    if(node->contiguous || !node->left || !node->right)
+      return true;
 
-  return set_contains(first->left.data(), index) || set_contains(first->right.data(), index);
+    if(index < node->left->end)
+      node = node->left.data();
+    else
+      node = node->right.data();
+  }
+  
+  return false;
 }
 
 SetNode* set_subtract(SetNode* first, SetNode* second)
@@ -964,8 +971,7 @@
 {
   if(!d->m_tree)
     return false;
-  set_contains(d->m_tree.data(), index);
-  return true;
+  return set_contains(d->m_tree.data(), index);
 }
 
 Set Set::operator +(const Set& first) const
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic