From 520c2d1e1f4af61581be82a22074af4ac136c4ba Mon Sep 17 00:00:00 2001 From: srn Date: Thu, 1 Nov 2007 09:08:14 +0000 Subject: [PATCH] Optimized method FindChild --- src/DF/DF_Label.cxx | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/DF/DF_Label.cxx b/src/DF/DF_Label.cxx index b44b19bf9..682a4ca5a 100644 --- a/src/DF/DF_Label.cxx +++ b/src/DF/DF_Label.cxx @@ -296,17 +296,22 @@ DF_Label DF_Label::FindChild(int theTag, bool isCreate) DF_LabelNode *aLabel = NULL, *aPrevious = NULL, *aNext = NULL; if(!_node->_firstChild && !isCreate) return DF_Label(); - aLabel = _node->_firstChild; - while(aLabel) { - if(aLabel->_tag == theTag) return DF_Label(aLabel); - if(aLabel->_tag > theTag) { - aNext = aLabel; - break; + if(_node->_lastChild && _node->_lastChild->_tag < theTag) { //Incremental addition of children + aPrevious = _node->_lastChild; + } + else { + aLabel = _node->_firstChild; + while(aLabel) { + if(aLabel->_tag == theTag) return DF_Label(aLabel); + if(aLabel->_tag > theTag) { + aNext = aLabel; + break; + } + if(aLabel->_tag < theTag) aPrevious = aLabel; + aLabel = aLabel->_next; } - if(aLabel->_tag < theTag) aPrevious = aLabel; - aLabel = aLabel->_next; } - + if(!isCreate) return DF_Label(); DF_LabelNode* aChild = new DF_LabelNode(); @@ -326,7 +331,7 @@ DF_Label DF_Label::FindChild(int theTag, bool isCreate) } if(!_node->_firstChild || (aNext && aNext == _node->_firstChild) ) _node->_firstChild = aChild; - if(!_node->_lastChild && !aNext) _node->_lastChild = aChild; + if(!aNext) _node->_lastChild = aChild; return aChild; } -- 2.39.2