From 4857393413b90df04c3fcac4048319196b10dec9 Mon Sep 17 00:00:00 2001 From: kipp Date: Sun, 26 Apr 1998 03:13:20 +0000 Subject: [PATCH] Fixed compiler bugs/warnings --- base/src/nsBTree.cpp | 2 +- base/src/nsBTree.h | 3 +- base/src/nsRBTree.cpp | 421 ---------------------------- base/src/nsRBTree.h | 2 +- base/src/nsString.cpp | 12 +- gfx/src/nsTransform2D.cpp | 4 +- gfx/tests/TestColorNames.cpp | 2 +- htmlparser/src/CNavDTD.cpp | 2 - htmlparser/src/COtherDTD.cpp | 2 - parser/htmlparser/src/CNavDTD.cpp | 2 - parser/htmlparser/src/COtherDTD.cpp | 2 - string/obsolete/nsString.cpp | 12 +- view/src/nsScrollingView.cpp | 2 +- xpcom/ds/nsBTree.cpp | 2 +- xpcom/ds/nsBTree.h | 3 +- xpcom/ds/nsRBTree.cpp | 421 ---------------------------- xpcom/ds/nsRBTree.h | 2 +- xpcom/ds/nsString.cpp | 12 +- xpcom/string/obsolete/nsString.cpp | 12 +- 19 files changed, 35 insertions(+), 885 deletions(-) diff --git a/base/src/nsBTree.cpp b/base/src/nsBTree.cpp index bc09dcd655d..a771d94aaac 100644 --- a/base/src/nsBTree.cpp +++ b/base/src/nsBTree.cpp @@ -190,7 +190,7 @@ nsNode* nsBTree::Remove(nsNode& aNode){ if(node2!=node3) (*node3)==(*node2); - if(node2->mColor=nsNode::eBlack) + if(node2->mColor == nsNode::eBlack) ReBalance(*node1); delete node2; diff --git a/base/src/nsBTree.h b/base/src/nsBTree.h index 75743298d5f..62b79b8b654 100644 --- a/base/src/nsBTree.h +++ b/base/src/nsBTree.h @@ -279,4 +279,5 @@ protected: nsNode* mRoot; }; -#endif \ No newline at end of file +#endif + diff --git a/base/src/nsRBTree.cpp b/base/src/nsRBTree.cpp index ed2f0ad3bde..e69de29bb2d 100644 --- a/base/src/nsRBTree.cpp +++ b/base/src/nsRBTree.cpp @@ -1,421 +0,0 @@ - -/** - * This file defines the binary tree class and it - * nsNode child class. - * - * This simple version stores nodes, and the - * nodes store void* ptrs. - * - * @update gess 4/11/98 - * @param - * @return - */ - -#include "nsRBTree.h" - - - -/************************************************** - Here comes the nsRBTree class... - *************************************************/ - -/** - * nsRBTree constructor - * - * @update gess 4/11/98 - */ -nsRBTree::nsRBTree() : nsBTree() { - mRoot=0; -} - -/** - * nsRBTree constructor - * - * @update gess 4/11/98 - */ -nsRBTree::nsRBTree(const nsRBTree& aCopy) : nsBTree(aCopy) { - mRoot=aCopy.mRoot; -} - -/** - * nsRBTree destructor - * - * @update gess 4/11/98 - * @param - * @return - */ -nsRBTree::~nsRBTree(){ - if(mRoot){ - //walk the tree and destroy the children. - } -} - - -/** - * Given a node, we're supposed to add it into - * our tree. - * - * @update gess 4/11/98 - * @param - * @return - */ -nsNode* nsRBTree::Add(nsNode& aNode){ - - nsBTree::Add(aNode); - - nsNode* node1=&aNode; - nsNode* node2=0; - - node1->mColor=nsNode::eRed; - - while((node1!=mRoot) && (node1->mParent->mColor==nsNode::eRed)) { - if(node1->mParent==node1->mParent->mParent->mLeft) { - node2=node1->mParent->mParent->mLeft; - if(node2->mColor==nsNode::eRed) { - node1->mParent->mColor=nsNode::eBlack; - node2->mColor=nsNode::eBlack; - node1->mParent->mParent->mColor=nsNode::eRed; - node1=node1->mParent->mParent; - } - else { - if(node1==node1->mParent->mRight) { - node1=node1->mParent; - ShiftLeft(*node1); - } - node1->mParent->mColor=nsNode::eBlack; - node1->mParent->mParent->mColor=nsNode::eRed; - ShiftRight(*node1->mParent->mParent); - } - } - else { - node2=node1->mParent->mParent->mRight; - if (node2->mColor==nsNode::eRed){ - node1->mParent->mColor=nsNode::eBlack; - node2->mColor=nsNode::eBlack; - node1->mParent->mParent->mColor=nsNode::eRed; - node1=node1->mParent->mParent; - } - else { - if (node1==node1->mParent->mLeft) { - node1=node1->mParent; - ShiftRight(*node1); - } - node1->mParent->mColor=nsNode::eBlack; - node1->mParent->mParent->mColor=nsNode::eRed; - ShiftLeft(*node1->mParent->mParent); - } - } - } - - mRoot->mColor=nsNode::eBlack; - return &aNode; -} - - -/** - * Retrive the first node in the tree - * - * @update gess 4/11/98 - * @param - * @return - */ -nsNode* nsRBTree::First(){ - nsNode* result=First(*mRoot); - return result; -} - -/** - * Retrieve the first node given a starting node - * - * @update gess 4/11/98 - * @param aNode -- - * @return node ptr or null - */ -nsNode* nsRBTree::First(nsNode& aNode){ - nsNode* result=0; - - if(mRoot) { - result=mRoot; - while(result->GetLeftNode()) { - result=result->GetLeftNode(); - } - } - return result; -} - -/** - * Find the last node in the tree - * - * @update gess 4/11/98 - * @param - * @return node ptr or null - */ -nsNode* nsRBTree::Last(){ - nsNode* result=Last(*mRoot); - return result; -} - -/** - * Find the last node from a given node - * - * @update gess 4/11/98 - * @param aNode -- node ptr to start from - * @return node ptr or null - */ -nsNode* nsRBTree::Last(nsNode& aNode){ - nsNode* result=0; - - if(mRoot) { - result=mRoot; - while(result->GetRightNode()) { - result=result->GetRightNode(); - } - } - return result; -} - - -/** - * Retrieve the node that preceeds the given node - * - * @update gess 4/11/98 - * @param aNode -- node to find precedent of - * @return preceeding node ptr, or null - */ -nsNode* nsRBTree::Before(nsNode& aNode){ - - if(aNode.GetLeftNode()) - return Last(*aNode.GetLeftNode()); - - //otherwise... - - nsNode* node1=&aNode; - nsNode* node2=aNode.GetParentNode(); - - while((node2) && (node1==node2->GetLeftNode())) { - node1=node2; - node2=node2->GetParentNode(); - } - return node2; -} - - -/** - * Retrieve a ptr to the node following the given node - * - * @update gess 4/11/98 - * @param aNode -- node to find successor node from - * @return node ptr or null - */ -nsNode* nsRBTree::After(nsNode& aNode){ - - if(aNode.GetRightNode()) - return First(*aNode.GetRightNode()); - - //otherwise... - - nsNode* node1=&aNode; - nsNode* node2=aNode.GetParentNode(); - - while((node2) && (node1==node2->GetRightNode())) { - node1=node2; - node2=node2->GetParentNode(); - } - - return node2; -} - -/** - * Find a (given) node in the tree - * - * @update gess 4/11/98 - * @param node to find in the tree - * @return node ptr (if found) or null - */ -nsNode* nsRBTree::Find(nsNode& aNode){ - nsNode* result=mRoot; - - while((result) && (!((*result)==aNode))) { - if(aNode<*result) - result=result->mLeft; - else result=result->mRight; - } - return result; -} - - -/** - * Causes a shift to the left, to keep the - * underlying RB data in balance - * - * @update gess 4/11/98 - * @param - * @return this - */ -nsRBTree& nsRBTree::ShiftLeft(nsNode& aNode){ - - nsNode* temp= aNode.mRight; - - aNode.mRight=temp->mLeft; - if(temp->mLeft) - temp->mRight->mParent=&aNode; - temp->mParent= aNode.mParent; - if (aNode.mParent) { - if (&aNode==aNode.mParent->mLeft) - aNode.mParent->mLeft=temp; - else aNode.mParent->mRight=temp; - } - else mRoot=temp; - temp->mLeft=&aNode;; - aNode.mParent=temp; - return *this; -} - -/** - * Causes a shift right to occur, to keep the - * underlying RB data in balance - * - * @update gess 4/11/98 - * @param aNode -- node at which to perform shift - * @return this - */ -nsRBTree& nsRBTree::ShiftRight(nsNode& aNode){ - - nsNode* temp=aNode.mLeft; - - aNode.mLeft=temp->mRight; - if(temp->mRight) - temp->mRight->mParent=&aNode; - temp->mParent=aNode.mParent; - if(aNode.mParent){ - if(&aNode==aNode.mParent->mRight) - aNode.mParent->mRight=temp; - else aNode.mParent->mLeft=temp; - } - else mRoot=temp; - temp->mRight=&aNode; - aNode.mParent=temp; - return *this; -} - -/** - * Rebalances tree around the given node. This only - * needs to be called after a node is deleted. - * - * @update gess 4/11/98 - * @param aNode -- node to balance around - * @return this - */ -nsBTree& nsRBTree::ReBalance(nsNode& aNode){ - - nsNode* node1=&aNode; - nsNode* node2=0; - - while ((node1!=mRoot) && (node1->mColor==nsNode::eBlack)) { - if(node1==node1->mParent->mLeft) { - node2=node1->mParent->mRight; - if(node2->mColor==nsNode::eRed) { - node2->mColor=nsNode::eBlack; - node1->mParent->mColor=nsNode::eRed; - ShiftLeft(*node1->mParent); - node2=node1->mParent->mRight; - } - - if((node2->mLeft->mColor=nsNode::eBlack) && (node2->mRight->mColor=nsNode::eBlack)) { - node2->mColor=nsNode::eRed; - node1=node1->mParent; - } - else { - if(node2->mRight->mColor=nsNode::eBlack) { - node2->mLeft->mColor=nsNode::eBlack; - node2->mColor=nsNode::eRed; - ShiftRight(*node2); - node2=node1->mParent->mRight; - } - - node2->mColor=node1->mParent->mColor; - node1->mParent->mColor=nsNode::eBlack; - node2->mRight->mColor=nsNode::eBlack; - ShiftLeft(*node1->mParent); - node1=mRoot; - } //else - } - else { - node2=node1->mParent->mLeft; - if(node2->mColor==nsNode::eRed) { - node2->mColor=nsNode::eBlack; - node1->mParent->mColor=nsNode::eRed; - ShiftRight(*node1->mParent); - node2=node1->mParent->mLeft; - } - - if((node2->mRight->mColor=nsNode::eBlack) && (node2->mLeft->mColor=nsNode::eBlack)) { - node2->mColor=nsNode::eRed; - node1=node1->mParent; - } - else { - if(node2->mLeft->mColor=nsNode::eBlack){ - node2->mRight->mColor=nsNode::eBlack; - node2->mColor=nsNode::eRed; - ShiftLeft(*node2); - node2=node1->mParent->mLeft; - } - - node2->mColor=node1->mParent->mColor; - node1->mParent->mColor=nsNode::eBlack; - node2->mLeft->mColor=nsNode::eBlack; - ShiftRight(*node1->mParent); - node1=mRoot; - } //else - } //if - } //while - - node1->mColor=nsNode::eBlack; - return *this; -} - -/************************************************** - Here comes the nsRBTreeIterator class... - *************************************************/ - -/** - * - * - * @update gess 4/11/98 - * @param - * @return - */ -nsRBTreeIterator::nsRBTreeIterator(const nsRBTree& aTree) : mTree(aTree) { -} - -/** - * copy constructor - * - * @update gess 4/11/98 - * @param aCopy is the object you want to copy from - * @return newly constructed object - */ -nsRBTreeIterator::nsRBTreeIterator(const nsRBTreeIterator& aCopy) : mTree(aCopy.mTree) { -} - -/** - * Destructor method - * - * @update gess 4/11/98 - */ -nsRBTreeIterator::~nsRBTreeIterator(){ -} - -/** - * This method iterates over the tree, calling - * aFunctor for each node. - * - * @update gess 4/11/98 - * @param aFunctor -- object to call for each node - * @param aNode -- node at which to start iteration - * @return this - */ -const nsRBTreeIterator& nsRBTreeIterator::ForEach(nsNodeFunctor& aFunctor) const{ - mTree.ForEach(aFunctor); - return *this; -} diff --git a/base/src/nsRBTree.h b/base/src/nsRBTree.h index 71423a3ee31..c91241b2bb3 100644 --- a/base/src/nsRBTree.h +++ b/base/src/nsRBTree.h @@ -220,4 +220,4 @@ protected: }; -#endif \ No newline at end of file +#endif diff --git a/base/src/nsString.cpp b/base/src/nsString.cpp index 8e45375800a..559280b9c0c 100644 --- a/base/src/nsString.cpp +++ b/base/src/nsString.cpp @@ -530,15 +530,15 @@ float nsString::ToFloat(PRInt32* aErrorCode) const { char buf[40]; if (mLength > sizeof(buf)-1) { - *aErrorCode = NS_ERROR_ILLEGAL_VALUE; + *aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE; return 0.0f; } char* cp = ToCString(buf, sizeof(buf)); float f = (float) PR_strtod(cp, &cp); if (*cp != 0) { - *aErrorCode = NS_ERROR_ILLEGAL_VALUE; + *aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE; } - *aErrorCode = NS_OK; + *aErrorCode = (PRInt32) NS_OK; return f; } @@ -562,7 +562,7 @@ PRInt32 nsString::ToInteger(PRInt32* aErrorCode) const { cp++; } if (cp == end) { - *aErrorCode = NS_ERROR_ILLEGAL_VALUE; + *aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE; return rv; } @@ -572,7 +572,7 @@ PRInt32 nsString::ToInteger(PRInt32* aErrorCode) const { sign = *cp++; } if (cp == end) { - *aErrorCode = NS_ERROR_ILLEGAL_VALUE; + *aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE; return rv; } @@ -580,7 +580,7 @@ PRInt32 nsString::ToInteger(PRInt32* aErrorCode) const { while (cp < end) { PRUnichar ch = *cp++; if ((ch < '0') || (ch > '9')) { - *aErrorCode = NS_ERROR_ILLEGAL_VALUE; + *aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE; break; } rv = rv * 10 + (ch - '0'); diff --git a/gfx/src/nsTransform2D.cpp b/gfx/src/nsTransform2D.cpp index 5670f7cc464..59633af4fac 100644 --- a/gfx/src/nsTransform2D.cpp +++ b/gfx/src/nsTransform2D.cpp @@ -214,7 +214,7 @@ void nsTransform2D :: Concatenate(nsTransform2D *newxform) void nsTransform2D :: PreConcatenate(nsTransform2D *newxform) { float temp00, temp01, temp10, temp11, temp20, temp21; - float new00, new01, new10, new11, new20, new21; + float new00, new01, new10, new11; //this is totally unoptimized MMP @@ -229,8 +229,6 @@ void nsTransform2D :: PreConcatenate(nsTransform2D *newxform) new01 = newxform->m01; new10 = newxform->m10; new11 = newxform->m11; - new20 = newxform->m20; - new21 = newxform->m21; m00 = temp00 * new00 + temp01 * new10; // + temp02 * new20 == 0 m01 = temp00 * new01 + temp01 * new11; // + temp02 * new21 == 0 diff --git a/gfx/tests/TestColorNames.cpp b/gfx/tests/TestColorNames.cpp index 3b439222635..e332c726e2e 100644 --- a/gfx/tests/TestColorNames.cpp +++ b/gfx/tests/TestColorNames.cpp @@ -109,5 +109,5 @@ int main(int argc, char** argv) } } - return 0; + return rv; } diff --git a/htmlparser/src/CNavDTD.cpp b/htmlparser/src/CNavDTD.cpp index d938687b6da..6e6c9c4c6c7 100644 --- a/htmlparser/src/CNavDTD.cpp +++ b/htmlparser/src/CNavDTD.cpp @@ -529,8 +529,6 @@ PRBool CNavDTD::CanContainIndirect(PRInt32 aParent,PRInt32 aChild) const { } break; - result=PR_TRUE; break; - default: break; } diff --git a/htmlparser/src/COtherDTD.cpp b/htmlparser/src/COtherDTD.cpp index fc5103ec05e..c9562d2ebd6 100644 --- a/htmlparser/src/COtherDTD.cpp +++ b/htmlparser/src/COtherDTD.cpp @@ -503,8 +503,6 @@ PRBool COtherDTD::CanContainIndirect(PRInt32 aParent,PRInt32 aChild) const { } break; - result=PR_TRUE; break; - default: break; } diff --git a/parser/htmlparser/src/CNavDTD.cpp b/parser/htmlparser/src/CNavDTD.cpp index d938687b6da..6e6c9c4c6c7 100644 --- a/parser/htmlparser/src/CNavDTD.cpp +++ b/parser/htmlparser/src/CNavDTD.cpp @@ -529,8 +529,6 @@ PRBool CNavDTD::CanContainIndirect(PRInt32 aParent,PRInt32 aChild) const { } break; - result=PR_TRUE; break; - default: break; } diff --git a/parser/htmlparser/src/COtherDTD.cpp b/parser/htmlparser/src/COtherDTD.cpp index fc5103ec05e..c9562d2ebd6 100644 --- a/parser/htmlparser/src/COtherDTD.cpp +++ b/parser/htmlparser/src/COtherDTD.cpp @@ -503,8 +503,6 @@ PRBool COtherDTD::CanContainIndirect(PRInt32 aParent,PRInt32 aChild) const { } break; - result=PR_TRUE; break; - default: break; } diff --git a/string/obsolete/nsString.cpp b/string/obsolete/nsString.cpp index 8e45375800a..559280b9c0c 100644 --- a/string/obsolete/nsString.cpp +++ b/string/obsolete/nsString.cpp @@ -530,15 +530,15 @@ float nsString::ToFloat(PRInt32* aErrorCode) const { char buf[40]; if (mLength > sizeof(buf)-1) { - *aErrorCode = NS_ERROR_ILLEGAL_VALUE; + *aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE; return 0.0f; } char* cp = ToCString(buf, sizeof(buf)); float f = (float) PR_strtod(cp, &cp); if (*cp != 0) { - *aErrorCode = NS_ERROR_ILLEGAL_VALUE; + *aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE; } - *aErrorCode = NS_OK; + *aErrorCode = (PRInt32) NS_OK; return f; } @@ -562,7 +562,7 @@ PRInt32 nsString::ToInteger(PRInt32* aErrorCode) const { cp++; } if (cp == end) { - *aErrorCode = NS_ERROR_ILLEGAL_VALUE; + *aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE; return rv; } @@ -572,7 +572,7 @@ PRInt32 nsString::ToInteger(PRInt32* aErrorCode) const { sign = *cp++; } if (cp == end) { - *aErrorCode = NS_ERROR_ILLEGAL_VALUE; + *aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE; return rv; } @@ -580,7 +580,7 @@ PRInt32 nsString::ToInteger(PRInt32* aErrorCode) const { while (cp < end) { PRUnichar ch = *cp++; if ((ch < '0') || (ch > '9')) { - *aErrorCode = NS_ERROR_ILLEGAL_VALUE; + *aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE; break; } rv = rv * 10 + (ch - '0'); diff --git a/view/src/nsScrollingView.cpp b/view/src/nsScrollingView.cpp index cd7c79709ec..acff384b0ae 100644 --- a/view/src/nsScrollingView.cpp +++ b/view/src/nsScrollingView.cpp @@ -422,4 +422,4 @@ void nsScrollingView :: ComputeScrollArea(nsIView *aView, nsRect &aRect, nsIView *view = aView->GetChild(cnt); ComputeScrollArea(view, aRect, aOffX, aOffY); } -} \ No newline at end of file +} diff --git a/xpcom/ds/nsBTree.cpp b/xpcom/ds/nsBTree.cpp index bc09dcd655d..a771d94aaac 100644 --- a/xpcom/ds/nsBTree.cpp +++ b/xpcom/ds/nsBTree.cpp @@ -190,7 +190,7 @@ nsNode* nsBTree::Remove(nsNode& aNode){ if(node2!=node3) (*node3)==(*node2); - if(node2->mColor=nsNode::eBlack) + if(node2->mColor == nsNode::eBlack) ReBalance(*node1); delete node2; diff --git a/xpcom/ds/nsBTree.h b/xpcom/ds/nsBTree.h index 75743298d5f..62b79b8b654 100644 --- a/xpcom/ds/nsBTree.h +++ b/xpcom/ds/nsBTree.h @@ -279,4 +279,5 @@ protected: nsNode* mRoot; }; -#endif \ No newline at end of file +#endif + diff --git a/xpcom/ds/nsRBTree.cpp b/xpcom/ds/nsRBTree.cpp index ed2f0ad3bde..e69de29bb2d 100644 --- a/xpcom/ds/nsRBTree.cpp +++ b/xpcom/ds/nsRBTree.cpp @@ -1,421 +0,0 @@ - -/** - * This file defines the binary tree class and it - * nsNode child class. - * - * This simple version stores nodes, and the - * nodes store void* ptrs. - * - * @update gess 4/11/98 - * @param - * @return - */ - -#include "nsRBTree.h" - - - -/************************************************** - Here comes the nsRBTree class... - *************************************************/ - -/** - * nsRBTree constructor - * - * @update gess 4/11/98 - */ -nsRBTree::nsRBTree() : nsBTree() { - mRoot=0; -} - -/** - * nsRBTree constructor - * - * @update gess 4/11/98 - */ -nsRBTree::nsRBTree(const nsRBTree& aCopy) : nsBTree(aCopy) { - mRoot=aCopy.mRoot; -} - -/** - * nsRBTree destructor - * - * @update gess 4/11/98 - * @param - * @return - */ -nsRBTree::~nsRBTree(){ - if(mRoot){ - //walk the tree and destroy the children. - } -} - - -/** - * Given a node, we're supposed to add it into - * our tree. - * - * @update gess 4/11/98 - * @param - * @return - */ -nsNode* nsRBTree::Add(nsNode& aNode){ - - nsBTree::Add(aNode); - - nsNode* node1=&aNode; - nsNode* node2=0; - - node1->mColor=nsNode::eRed; - - while((node1!=mRoot) && (node1->mParent->mColor==nsNode::eRed)) { - if(node1->mParent==node1->mParent->mParent->mLeft) { - node2=node1->mParent->mParent->mLeft; - if(node2->mColor==nsNode::eRed) { - node1->mParent->mColor=nsNode::eBlack; - node2->mColor=nsNode::eBlack; - node1->mParent->mParent->mColor=nsNode::eRed; - node1=node1->mParent->mParent; - } - else { - if(node1==node1->mParent->mRight) { - node1=node1->mParent; - ShiftLeft(*node1); - } - node1->mParent->mColor=nsNode::eBlack; - node1->mParent->mParent->mColor=nsNode::eRed; - ShiftRight(*node1->mParent->mParent); - } - } - else { - node2=node1->mParent->mParent->mRight; - if (node2->mColor==nsNode::eRed){ - node1->mParent->mColor=nsNode::eBlack; - node2->mColor=nsNode::eBlack; - node1->mParent->mParent->mColor=nsNode::eRed; - node1=node1->mParent->mParent; - } - else { - if (node1==node1->mParent->mLeft) { - node1=node1->mParent; - ShiftRight(*node1); - } - node1->mParent->mColor=nsNode::eBlack; - node1->mParent->mParent->mColor=nsNode::eRed; - ShiftLeft(*node1->mParent->mParent); - } - } - } - - mRoot->mColor=nsNode::eBlack; - return &aNode; -} - - -/** - * Retrive the first node in the tree - * - * @update gess 4/11/98 - * @param - * @return - */ -nsNode* nsRBTree::First(){ - nsNode* result=First(*mRoot); - return result; -} - -/** - * Retrieve the first node given a starting node - * - * @update gess 4/11/98 - * @param aNode -- - * @return node ptr or null - */ -nsNode* nsRBTree::First(nsNode& aNode){ - nsNode* result=0; - - if(mRoot) { - result=mRoot; - while(result->GetLeftNode()) { - result=result->GetLeftNode(); - } - } - return result; -} - -/** - * Find the last node in the tree - * - * @update gess 4/11/98 - * @param - * @return node ptr or null - */ -nsNode* nsRBTree::Last(){ - nsNode* result=Last(*mRoot); - return result; -} - -/** - * Find the last node from a given node - * - * @update gess 4/11/98 - * @param aNode -- node ptr to start from - * @return node ptr or null - */ -nsNode* nsRBTree::Last(nsNode& aNode){ - nsNode* result=0; - - if(mRoot) { - result=mRoot; - while(result->GetRightNode()) { - result=result->GetRightNode(); - } - } - return result; -} - - -/** - * Retrieve the node that preceeds the given node - * - * @update gess 4/11/98 - * @param aNode -- node to find precedent of - * @return preceeding node ptr, or null - */ -nsNode* nsRBTree::Before(nsNode& aNode){ - - if(aNode.GetLeftNode()) - return Last(*aNode.GetLeftNode()); - - //otherwise... - - nsNode* node1=&aNode; - nsNode* node2=aNode.GetParentNode(); - - while((node2) && (node1==node2->GetLeftNode())) { - node1=node2; - node2=node2->GetParentNode(); - } - return node2; -} - - -/** - * Retrieve a ptr to the node following the given node - * - * @update gess 4/11/98 - * @param aNode -- node to find successor node from - * @return node ptr or null - */ -nsNode* nsRBTree::After(nsNode& aNode){ - - if(aNode.GetRightNode()) - return First(*aNode.GetRightNode()); - - //otherwise... - - nsNode* node1=&aNode; - nsNode* node2=aNode.GetParentNode(); - - while((node2) && (node1==node2->GetRightNode())) { - node1=node2; - node2=node2->GetParentNode(); - } - - return node2; -} - -/** - * Find a (given) node in the tree - * - * @update gess 4/11/98 - * @param node to find in the tree - * @return node ptr (if found) or null - */ -nsNode* nsRBTree::Find(nsNode& aNode){ - nsNode* result=mRoot; - - while((result) && (!((*result)==aNode))) { - if(aNode<*result) - result=result->mLeft; - else result=result->mRight; - } - return result; -} - - -/** - * Causes a shift to the left, to keep the - * underlying RB data in balance - * - * @update gess 4/11/98 - * @param - * @return this - */ -nsRBTree& nsRBTree::ShiftLeft(nsNode& aNode){ - - nsNode* temp= aNode.mRight; - - aNode.mRight=temp->mLeft; - if(temp->mLeft) - temp->mRight->mParent=&aNode; - temp->mParent= aNode.mParent; - if (aNode.mParent) { - if (&aNode==aNode.mParent->mLeft) - aNode.mParent->mLeft=temp; - else aNode.mParent->mRight=temp; - } - else mRoot=temp; - temp->mLeft=&aNode;; - aNode.mParent=temp; - return *this; -} - -/** - * Causes a shift right to occur, to keep the - * underlying RB data in balance - * - * @update gess 4/11/98 - * @param aNode -- node at which to perform shift - * @return this - */ -nsRBTree& nsRBTree::ShiftRight(nsNode& aNode){ - - nsNode* temp=aNode.mLeft; - - aNode.mLeft=temp->mRight; - if(temp->mRight) - temp->mRight->mParent=&aNode; - temp->mParent=aNode.mParent; - if(aNode.mParent){ - if(&aNode==aNode.mParent->mRight) - aNode.mParent->mRight=temp; - else aNode.mParent->mLeft=temp; - } - else mRoot=temp; - temp->mRight=&aNode; - aNode.mParent=temp; - return *this; -} - -/** - * Rebalances tree around the given node. This only - * needs to be called after a node is deleted. - * - * @update gess 4/11/98 - * @param aNode -- node to balance around - * @return this - */ -nsBTree& nsRBTree::ReBalance(nsNode& aNode){ - - nsNode* node1=&aNode; - nsNode* node2=0; - - while ((node1!=mRoot) && (node1->mColor==nsNode::eBlack)) { - if(node1==node1->mParent->mLeft) { - node2=node1->mParent->mRight; - if(node2->mColor==nsNode::eRed) { - node2->mColor=nsNode::eBlack; - node1->mParent->mColor=nsNode::eRed; - ShiftLeft(*node1->mParent); - node2=node1->mParent->mRight; - } - - if((node2->mLeft->mColor=nsNode::eBlack) && (node2->mRight->mColor=nsNode::eBlack)) { - node2->mColor=nsNode::eRed; - node1=node1->mParent; - } - else { - if(node2->mRight->mColor=nsNode::eBlack) { - node2->mLeft->mColor=nsNode::eBlack; - node2->mColor=nsNode::eRed; - ShiftRight(*node2); - node2=node1->mParent->mRight; - } - - node2->mColor=node1->mParent->mColor; - node1->mParent->mColor=nsNode::eBlack; - node2->mRight->mColor=nsNode::eBlack; - ShiftLeft(*node1->mParent); - node1=mRoot; - } //else - } - else { - node2=node1->mParent->mLeft; - if(node2->mColor==nsNode::eRed) { - node2->mColor=nsNode::eBlack; - node1->mParent->mColor=nsNode::eRed; - ShiftRight(*node1->mParent); - node2=node1->mParent->mLeft; - } - - if((node2->mRight->mColor=nsNode::eBlack) && (node2->mLeft->mColor=nsNode::eBlack)) { - node2->mColor=nsNode::eRed; - node1=node1->mParent; - } - else { - if(node2->mLeft->mColor=nsNode::eBlack){ - node2->mRight->mColor=nsNode::eBlack; - node2->mColor=nsNode::eRed; - ShiftLeft(*node2); - node2=node1->mParent->mLeft; - } - - node2->mColor=node1->mParent->mColor; - node1->mParent->mColor=nsNode::eBlack; - node2->mLeft->mColor=nsNode::eBlack; - ShiftRight(*node1->mParent); - node1=mRoot; - } //else - } //if - } //while - - node1->mColor=nsNode::eBlack; - return *this; -} - -/************************************************** - Here comes the nsRBTreeIterator class... - *************************************************/ - -/** - * - * - * @update gess 4/11/98 - * @param - * @return - */ -nsRBTreeIterator::nsRBTreeIterator(const nsRBTree& aTree) : mTree(aTree) { -} - -/** - * copy constructor - * - * @update gess 4/11/98 - * @param aCopy is the object you want to copy from - * @return newly constructed object - */ -nsRBTreeIterator::nsRBTreeIterator(const nsRBTreeIterator& aCopy) : mTree(aCopy.mTree) { -} - -/** - * Destructor method - * - * @update gess 4/11/98 - */ -nsRBTreeIterator::~nsRBTreeIterator(){ -} - -/** - * This method iterates over the tree, calling - * aFunctor for each node. - * - * @update gess 4/11/98 - * @param aFunctor -- object to call for each node - * @param aNode -- node at which to start iteration - * @return this - */ -const nsRBTreeIterator& nsRBTreeIterator::ForEach(nsNodeFunctor& aFunctor) const{ - mTree.ForEach(aFunctor); - return *this; -} diff --git a/xpcom/ds/nsRBTree.h b/xpcom/ds/nsRBTree.h index 71423a3ee31..c91241b2bb3 100644 --- a/xpcom/ds/nsRBTree.h +++ b/xpcom/ds/nsRBTree.h @@ -220,4 +220,4 @@ protected: }; -#endif \ No newline at end of file +#endif diff --git a/xpcom/ds/nsString.cpp b/xpcom/ds/nsString.cpp index 8e45375800a..559280b9c0c 100644 --- a/xpcom/ds/nsString.cpp +++ b/xpcom/ds/nsString.cpp @@ -530,15 +530,15 @@ float nsString::ToFloat(PRInt32* aErrorCode) const { char buf[40]; if (mLength > sizeof(buf)-1) { - *aErrorCode = NS_ERROR_ILLEGAL_VALUE; + *aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE; return 0.0f; } char* cp = ToCString(buf, sizeof(buf)); float f = (float) PR_strtod(cp, &cp); if (*cp != 0) { - *aErrorCode = NS_ERROR_ILLEGAL_VALUE; + *aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE; } - *aErrorCode = NS_OK; + *aErrorCode = (PRInt32) NS_OK; return f; } @@ -562,7 +562,7 @@ PRInt32 nsString::ToInteger(PRInt32* aErrorCode) const { cp++; } if (cp == end) { - *aErrorCode = NS_ERROR_ILLEGAL_VALUE; + *aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE; return rv; } @@ -572,7 +572,7 @@ PRInt32 nsString::ToInteger(PRInt32* aErrorCode) const { sign = *cp++; } if (cp == end) { - *aErrorCode = NS_ERROR_ILLEGAL_VALUE; + *aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE; return rv; } @@ -580,7 +580,7 @@ PRInt32 nsString::ToInteger(PRInt32* aErrorCode) const { while (cp < end) { PRUnichar ch = *cp++; if ((ch < '0') || (ch > '9')) { - *aErrorCode = NS_ERROR_ILLEGAL_VALUE; + *aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE; break; } rv = rv * 10 + (ch - '0'); diff --git a/xpcom/string/obsolete/nsString.cpp b/xpcom/string/obsolete/nsString.cpp index 8e45375800a..559280b9c0c 100644 --- a/xpcom/string/obsolete/nsString.cpp +++ b/xpcom/string/obsolete/nsString.cpp @@ -530,15 +530,15 @@ float nsString::ToFloat(PRInt32* aErrorCode) const { char buf[40]; if (mLength > sizeof(buf)-1) { - *aErrorCode = NS_ERROR_ILLEGAL_VALUE; + *aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE; return 0.0f; } char* cp = ToCString(buf, sizeof(buf)); float f = (float) PR_strtod(cp, &cp); if (*cp != 0) { - *aErrorCode = NS_ERROR_ILLEGAL_VALUE; + *aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE; } - *aErrorCode = NS_OK; + *aErrorCode = (PRInt32) NS_OK; return f; } @@ -562,7 +562,7 @@ PRInt32 nsString::ToInteger(PRInt32* aErrorCode) const { cp++; } if (cp == end) { - *aErrorCode = NS_ERROR_ILLEGAL_VALUE; + *aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE; return rv; } @@ -572,7 +572,7 @@ PRInt32 nsString::ToInteger(PRInt32* aErrorCode) const { sign = *cp++; } if (cp == end) { - *aErrorCode = NS_ERROR_ILLEGAL_VALUE; + *aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE; return rv; } @@ -580,7 +580,7 @@ PRInt32 nsString::ToInteger(PRInt32* aErrorCode) const { while (cp < end) { PRUnichar ch = *cp++; if ((ch < '0') || (ch > '9')) { - *aErrorCode = NS_ERROR_ILLEGAL_VALUE; + *aErrorCode = (PRInt32) NS_ERROR_ILLEGAL_VALUE; break; } rv = rv * 10 + (ch - '0');