From cda6f2b142e5c7512150357575ef57bfeb066562 Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Tue, 13 Feb 2007 16:23:19 +0000 Subject: [PATCH] Don't use a static nsTArray. Bug 369099, r=bernd, sr=roc git-svn-id: svn://10.0.0.236/trunk@220057 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/build/nsLayoutStatics.cpp | 8 ++++++ mozilla/layout/tables/nsCellMap.cpp | 32 +++++++++++++++++++----- mozilla/layout/tables/nsCellMap.h | 3 +++ 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/mozilla/layout/build/nsLayoutStatics.cpp b/mozilla/layout/build/nsLayoutStatics.cpp index c99c56fab6f..539b4a07de6 100644 --- a/mozilla/layout/build/nsLayoutStatics.cpp +++ b/mozilla/layout/build/nsLayoutStatics.cpp @@ -76,6 +76,7 @@ #include "nsXBLWindowKeyHandler.h" #include "txMozillaXSLTProcessor.h" #include "nsDOMStorage.h" +#include "nsCellMap.h" #ifdef MOZ_XUL #include "nsXULContentUtils.h" @@ -138,6 +139,12 @@ nsLayoutStatics::Initialize() return rv; } + rv = nsCellMap::Init(); + if (NS_FAILED(rv)) { + NS_ERROR("Could not initialize nsCellMap"); + return rv; + } + // Register all of our atoms once nsCSSAnonBoxes::AddRefAtoms(); nsCSSPseudoClasses::AddRefAtoms(); @@ -216,6 +223,7 @@ nsLayoutStatics::Shutdown() #ifdef DEBUG nsFrame::DisplayReflowShutdown(); #endif + nsCellMap::Shutdown(); // Release all of our atoms nsColorNames::ReleaseTable(); diff --git a/mozilla/layout/tables/nsCellMap.cpp b/mozilla/layout/tables/nsCellMap.cpp index 9ce5a905bd1..06efe8d24fa 100644 --- a/mozilla/layout/tables/nsCellMap.cpp +++ b/mozilla/layout/tables/nsCellMap.cpp @@ -42,7 +42,7 @@ #include "nsTableRowGroupFrame.h" // Empty static array used for SafeElementAt() calls on mRows. -static nsCellMap::CellDataArray sEmptyRow; +static nsCellMap::CellDataArray * sEmptyRow; // CellData @@ -1216,6 +1216,25 @@ nsCellMap::~nsCellMap() } } +/* static */ +nsresult +nsCellMap::Init() +{ + NS_ASSERTION(!sEmptyRow, "How did that happen?"); + sEmptyRow = new nsCellMap::CellDataArray(); + NS_ENSURE_TRUE(sEmptyRow, NS_ERROR_OUT_OF_MEMORY); + + return NS_OK; +} + +/* static */ +void +nsCellMap::Shutdown() +{ + delete sEmptyRow; + sEmptyRow = nsnull; +} + nsTableCellFrame* nsCellMap::GetCellFrame(PRInt32 aRowIndexIn, PRInt32 aColIndexIn, @@ -1234,7 +1253,7 @@ nsCellMap::GetCellFrame(PRInt32 aRowIndexIn, } CellData* data = - mRows.SafeElementAt(rowIndex, sEmptyRow).SafeElementAt(colIndex); + mRows.SafeElementAt(rowIndex, *sEmptyRow).SafeElementAt(colIndex); if (data) { return data->GetCellFrame(); } @@ -1993,7 +2012,7 @@ nsCellMap::GetRowSpanForNewCell(nsTableCellFrame* aCellFrameToAdd, PRBool nsCellMap::HasMoreThanOneCell(PRInt32 aRowIndex) const { - const CellDataArray& row = mRows.SafeElementAt(aRowIndex, sEmptyRow); + const CellDataArray& row = mRows.SafeElementAt(aRowIndex, *sEmptyRow); PRUint32 maxColIndex = row.Length(); PRUint32 count = 0; PRUint32 colIndex; @@ -2010,7 +2029,7 @@ PRBool nsCellMap::HasMoreThanOneCell(PRInt32 aRowIndex) const PRInt32 nsCellMap::GetNumCellsOriginatingInRow(PRInt32 aRowIndex) const { - const CellDataArray& row = mRows.SafeElementAt(aRowIndex, sEmptyRow); + const CellDataArray& row = mRows.SafeElementAt(aRowIndex, *sEmptyRow); PRUint32 count = 0; PRUint32 maxColIndex = row.Length(); PRUint32 colIndex; @@ -2533,7 +2552,7 @@ nsCellMap::IsZeroColSpan(PRInt32 aRowIndex, PRInt32 aColIndex) const { CellData* data = - mRows.SafeElementAt(aRowIndex, sEmptyRow).SafeElementAt(aColIndex); + mRows.SafeElementAt(aRowIndex, *sEmptyRow).SafeElementAt(aColIndex); return data && data->IsZeroColSpan(); } @@ -2541,7 +2560,8 @@ CellData* nsCellMap::GetDataAt(PRInt32 aMapRowIndex, PRInt32 aColIndex) const { - return mRows.SafeElementAt(aMapRowIndex, sEmptyRow).SafeElementAt(aColIndex); + return + mRows.SafeElementAt(aMapRowIndex, *sEmptyRow).SafeElementAt(aColIndex); } // only called if the cell at aMapRowIndex, aColIndex is null or dead diff --git a/mozilla/layout/tables/nsCellMap.h b/mozilla/layout/tables/nsCellMap.h index 2b648511464..15bd08697d4 100644 --- a/mozilla/layout/tables/nsCellMap.h +++ b/mozilla/layout/tables/nsCellMap.h @@ -288,6 +288,9 @@ public: */ ~nsCellMap(); + static nsresult Init(); + static void Shutdown(); + nsCellMap* GetNextSibling() const; void SetNextSibling(nsCellMap* aSibling);