]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/common/rbbinode.cpp
ICU-511.31.tar.gz
[apple/icu.git] / icuSources / common / rbbinode.cpp
index b873f2186317f85bbd49755b72f03aa4232163cc..49e0ad3dfa43a8e4bd367be7a0370a6059a084c7 100644 (file)
@@ -1,6 +1,6 @@
 /*
 ***************************************************************************
-*   Copyright (C) 2002-2003 International Business Machines Corporation   *
+*   Copyright (C) 2002-2008 International Business Machines Corporation   *
 *   and others. All rights reserved.                                      *
 ***************************************************************************
 */
@@ -33,8 +33,9 @@
 
 U_NAMESPACE_BEGIN
 
-int  RBBINode::gLastSerial = 0;
-
+#ifdef RBBI_DEBUG
+static int  gLastSerial = 0;
+#endif
 
 
 //-------------------------------------------------------------------------
@@ -43,7 +44,9 @@ int  RBBINode::gLastSerial = 0;
 //
 //-------------------------------------------------------------------------
 RBBINode::RBBINode(NodeType t) : UMemory() {
+#ifdef RBBI_DEBUG
     fSerialNum    = ++gLastSerial;
+#endif
     fType         = t;
     fParent       = NULL;
     fLeftChild    = NULL;
@@ -69,7 +72,9 @@ RBBINode::RBBINode(NodeType t) : UMemory() {
 
 
 RBBINode::RBBINode(const RBBINode &other) : UMemory(other) {
+#ifdef RBBI_DEBUG
     fSerialNum   = ++gLastSerial;
+#endif
     fType        = other.fType;
     fParent      = NULL;
     fLeftChild   = NULL;
@@ -144,13 +149,16 @@ RBBINode *RBBINode::cloneTree() {
         n = this;
     } else {
         n = new RBBINode(*this);
-        if (fLeftChild != NULL) {
-            n->fLeftChild          = fLeftChild->cloneTree();
-            n->fLeftChild->fParent = n;
-        }
-        if (fRightChild != NULL) {
-            n->fRightChild          = fRightChild->cloneTree();
-            n->fRightChild->fParent = n;
+        // Check for null pointer.
+        if (n != NULL) {
+            if (fLeftChild != NULL) {
+                n->fLeftChild          = fLeftChild->cloneTree();
+                n->fLeftChild->fParent = n;
+            }
+            if (fRightChild != NULL) {
+                n->fRightChild          = fRightChild->cloneTree();
+                n->fRightChild->fParent = n;
+            }
         }
     }
     return n;