From: srn Date: Thu, 1 Nov 2007 09:08:14 +0000 (+0000) Subject: Optimized method FindChild X-Git-Tag: V4_1_0a3~14 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=520c2d1e1f4af61581be82a22074af4ac136c4ba;p=modules%2Fkernel.git Optimized method FindChild --- 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; }