re-fix bug 166147 - autoinitialize mRefCnt to 0 for more efficient constructors

r=dougt, sr=jag, this time including some CSS stuff that has 31-bit refcounts.
This commit is contained in:
alecf%netscape.com 2002-09-17 04:49:28 +00:00
Родитель bae29568d0
Коммит 2eb51aa759
13 изменённых файлов: 43 добавлений и 12 удалений

Просмотреть файл

@ -75,14 +75,16 @@ void nsCSSRule::operator delete(void* ptr)
}
nsCSSRule::nsCSSRule(void)
: mSheet(nsnull),
: mRefCnt(0),
mSheet(nsnull),
mParentRule(nsnull)
{
NS_INIT_ISUPPORTS();
}
nsCSSRule::nsCSSRule(const nsCSSRule& aCopy)
: mSheet(aCopy.mSheet),
: mRefCnt(0),
mSheet(aCopy.mSheet),
mParentRule(aCopy.mParentRule)
{
NS_INIT_ISUPPORTS();

Просмотреть файл

@ -1767,6 +1767,7 @@ MOZ_DECL_CTOR_COUNTER(CSSStyleSheetImpl)
CSSStyleSheetImpl::CSSStyleSheetImpl()
: nsICSSStyleSheet(),
mRefCnt(0),
mTitle(),
mMedia(nsnull),
mFirstChild(nsnull),
@ -1788,6 +1789,7 @@ CSSStyleSheetImpl::CSSStyleSheetImpl()
CSSStyleSheetImpl::CSSStyleSheetImpl(const CSSStyleSheetImpl& aCopy)
: nsICSSStyleSheet(),
mRefCnt(0),
mTitle(aCopy.mTitle),
mMedia(nsnull),
mFirstChild(nsnull),

Просмотреть файл

@ -297,6 +297,7 @@ void HTMLCSSStyleSheetImpl::operator delete(void* ptr)
HTMLCSSStyleSheetImpl::HTMLCSSStyleSheetImpl()
: nsIHTMLCSSStyleSheet(),
mRefCnt(0),
mURL(nsnull),
mDocument(nsnull),
mFirstLineRule(nsnull),

Просмотреть файл

@ -858,6 +858,7 @@ void HTMLStyleSheetImpl::operator delete(void* ptr)
HTMLStyleSheetImpl::HTMLStyleSheetImpl(void)
: nsIHTMLStyleSheet(),
mRefCnt(0),
mURL(nsnull),
mDocument(nsnull),
mLinkRule(nsnull),

Просмотреть файл

@ -610,7 +610,7 @@ NS_IMPL_ADDREF(nsXULAttributes);
nsrefcnt
nsXULAttributes::Release()
{
mRefCnt--;
--mRefCnt;
NS_LOG_RELEASE(this, mRefCnt, "nsXULAttributes");
if (mRefCnt == 0) {
mRefCnt = 1; // stabilize (necessary for this class?)

Просмотреть файл

@ -208,10 +208,10 @@ public:
nsIURI* aDocumentURI,
nsISupportsArray* aNodeInfos) = 0;
void AddRef() { mRefCnt++; };
void AddRef() { ++mRefCnt; };
void Release()
{
mRefCnt--;
--mRefCnt;
if (mRefCnt == 0)
delete this;
};

Просмотреть файл

@ -75,14 +75,16 @@ void nsCSSRule::operator delete(void* ptr)
}
nsCSSRule::nsCSSRule(void)
: mSheet(nsnull),
: mRefCnt(0),
mSheet(nsnull),
mParentRule(nsnull)
{
NS_INIT_ISUPPORTS();
}
nsCSSRule::nsCSSRule(const nsCSSRule& aCopy)
: mSheet(aCopy.mSheet),
: mRefCnt(0),
mSheet(aCopy.mSheet),
mParentRule(aCopy.mParentRule)
{
NS_INIT_ISUPPORTS();

Просмотреть файл

@ -1767,6 +1767,7 @@ MOZ_DECL_CTOR_COUNTER(CSSStyleSheetImpl)
CSSStyleSheetImpl::CSSStyleSheetImpl()
: nsICSSStyleSheet(),
mRefCnt(0),
mTitle(),
mMedia(nsnull),
mFirstChild(nsnull),
@ -1788,6 +1789,7 @@ CSSStyleSheetImpl::CSSStyleSheetImpl()
CSSStyleSheetImpl::CSSStyleSheetImpl(const CSSStyleSheetImpl& aCopy)
: nsICSSStyleSheet(),
mRefCnt(0),
mTitle(aCopy.mTitle),
mMedia(nsnull),
mFirstChild(nsnull),

Просмотреть файл

@ -297,6 +297,7 @@ void HTMLCSSStyleSheetImpl::operator delete(void* ptr)
HTMLCSSStyleSheetImpl::HTMLCSSStyleSheetImpl()
: nsIHTMLCSSStyleSheet(),
mRefCnt(0),
mURL(nsnull),
mDocument(nsnull),
mFirstLineRule(nsnull),

Просмотреть файл

@ -858,6 +858,7 @@ void HTMLStyleSheetImpl::operator delete(void* ptr)
HTMLStyleSheetImpl::HTMLStyleSheetImpl(void)
: nsIHTMLStyleSheet(),
mRefCnt(0),
mURL(nsnull),
mDocument(nsnull),
mLinkRule(nsnull),

Просмотреть файл

@ -432,7 +432,7 @@ nsrefcnt nsViewManager::Release(void)
delete this;
return 0;
}
mRefCnt--;
--mRefCnt;
return mRefCnt;
}

Просмотреть файл

@ -85,7 +85,26 @@ extern "C" NS_COM void NS_CheckThreadSafe(void* owningThread,
#endif // !(defined(NS_DEBUG) && defined(NS_MT_SUPPORTED))
////////////////////////////////////////////////////////////////////////////////
class nsAutoRefCnt {
public:
nsAutoRefCnt() : mValue(0) {}
nsAutoRefCnt(nsrefcnt aValue) : mValue(aValue) {}
// only support prefix increment/decrement
nsrefcnt operator++() { return ++mValue; }
nsrefcnt operator--() { return --mValue; }
nsrefcnt operator=(nsrefcnt aValue) { return (mValue = aValue); }
operator nsrefcnt() const { return mValue; }
private:
// do not define these to enforce the faster prefix notation
nsrefcnt operator++(int);
nsrefcnt operator--(int);
nsrefcnt mValue;
};
///////////////////////////////////////////////////////////////////////////////
/**
* Declare the reference count variable and the implementations of the
@ -99,7 +118,7 @@ public: \
NS_IMETHOD_(nsrefcnt) AddRef(void); \
NS_IMETHOD_(nsrefcnt) Release(void); \
protected: \
nsrefcnt mRefCnt; \
nsAutoRefCnt mRefCnt; \
NS_DECL_OWNINGTHREAD \
public:
@ -110,7 +129,7 @@ public:
* Initialize the reference count variable. Add this to each and every
* constructor you implement.
*/
#define NS_INIT_ISUPPORTS() (mRefCnt = 0, NS_IMPL_OWNINGTHREAD())
#define NS_INIT_ISUPPORTS() (NS_IMPL_OWNINGTHREAD())
/**
* Use this macro to implement the AddRef method for a given <i>_class</i>

Просмотреть файл

@ -145,7 +145,7 @@ nsNativeAppSupportBase::CreateSplashScreen( nsISplashScreen **splash ) {
// Standard implementations of AddRef/Release/QueryInterface.
NS_IMETHODIMP_(nsrefcnt)
nsNativeAppSupportBase::AddRef() {
mRefCnt++;
++mRefCnt;
return mRefCnt;
}