From ff034cfbffd298a07baff495b2607cdb875e73b9 Mon Sep 17 00:00:00 2001 From: srn Date: Thu, 1 Nov 2007 11:39:28 +0000 Subject: [PATCH] Optimized FindChild method --- src/DF/DF_Label.cxx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/DF/DF_Label.cxx b/src/DF/DF_Label.cxx index 682a4ca5a..8bfd113ad 100644 --- a/src/DF/DF_Label.cxx +++ b/src/DF/DF_Label.cxx @@ -296,8 +296,16 @@ DF_Label DF_Label::FindChild(int theTag, bool isCreate) DF_LabelNode *aLabel = NULL, *aPrevious = NULL, *aNext = NULL; if(!_node->_firstChild && !isCreate) return DF_Label(); - if(_node->_lastChild && _node->_lastChild->_tag < theTag) { //Incremental addition of children - aPrevious = _node->_lastChild; + if(_node->_firstChild && _node->_firstChild->_tag == theTag) + return DF_Label(_node->_firstChild); + + if(_node->_lastChild) { + if( _node->_lastChild->_tag == theTag) { + return DF_Label(_node->_lastChild); + } + else if( _node->_lastChild->_tag < theTag) { //Incremental addition of children + aPrevious = _node->_lastChild; + } } else { aLabel = _node->_firstChild; @@ -331,7 +339,9 @@ DF_Label DF_Label::FindChild(int theTag, bool isCreate) } if(!_node->_firstChild || (aNext && aNext == _node->_firstChild) ) _node->_firstChild = aChild; - if(!aNext) _node->_lastChild = aChild; + if(!aNext) { + _node->_lastChild = aChild; + } return aChild; } -- 2.39.2