--HG--
extra : rebase_source : 698eae6de79ab094c978cf06f938dd2240a31bc8
This commit is contained in:
Olli Pettay 2009-06-16 12:15:46 +03:00
Родитель fe93cc2a50
Коммит ad1b3f2aef
2 изменённых файлов: 39 добавлений и 1 удалений

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

@ -81,6 +81,7 @@ public:
nsEventTargetChainItem* parent = item->mParent; nsEventTargetChainItem* parent = item->mParent;
item->~nsEventTargetChainItem(); item->~nsEventTargetChainItem();
aAllocator->Free(item, sizeof(nsEventTargetChainItem)); aAllocator->Free(item, sizeof(nsEventTargetChainItem));
--sCurrentEtciCount;
item = parent; item = parent;
} }
} }
@ -165,6 +166,13 @@ public:
*/ */
nsresult PostHandleEvent(nsEventChainPostVisitor& aVisitor); nsresult PostHandleEvent(nsEventChainPostVisitor& aVisitor);
static PRUint32 MaxEtciCount() { return sMaxEtciCount; }
static void ResetMaxEtciCount()
{
NS_ASSERTION(!sCurrentEtciCount, "Wrong time to call ResetMaxEtciCount()!");
sMaxEtciCount = 0;
}
nsCOMPtr<nsPIDOMEventTarget> mTarget; nsCOMPtr<nsPIDOMEventTarget> mTarget;
nsEventTargetChainItem* mChild; nsEventTargetChainItem* mChild;
@ -176,8 +184,14 @@ public:
nsCOMPtr<nsPIDOMEventTarget> mNewTarget; nsCOMPtr<nsPIDOMEventTarget> mNewTarget;
// Cache mTarget's event listener manager. // Cache mTarget's event listener manager.
nsCOMPtr<nsIEventListenerManager> mManager; nsCOMPtr<nsIEventListenerManager> mManager;
static PRUint32 sMaxEtciCount;
static PRUint32 sCurrentEtciCount;
}; };
PRUint32 nsEventTargetChainItem::sMaxEtciCount = 0;
PRUint32 nsEventTargetChainItem::sCurrentEtciCount = 0;
nsEventTargetChainItem::nsEventTargetChainItem(nsPIDOMEventTarget* aTarget, nsEventTargetChainItem::nsEventTargetChainItem(nsPIDOMEventTarget* aTarget,
nsEventTargetChainItem* aChild) nsEventTargetChainItem* aChild)
: mChild(aChild), mParent(nsnull), mFlags(0), mItemFlags(0) : mChild(aChild), mParent(nsnull), mFlags(0), mItemFlags(0)
@ -186,6 +200,10 @@ nsEventTargetChainItem::nsEventTargetChainItem(nsPIDOMEventTarget* aTarget,
if (mChild) { if (mChild) {
mChild->mParent = this; mChild->mParent = this;
} }
if (++sCurrentEtciCount > sMaxEtciCount) {
sMaxEtciCount = sCurrentEtciCount;
}
} }
nsresult nsresult
@ -347,6 +365,8 @@ nsEventTargetChainItem::HandleEventTargetChain(nsEventChainPostVisitor& aVisitor
return NS_OK; return NS_OK;
} }
#define NS_CHAIN_POOL_SIZE 128
class ChainItemPool { class ChainItemPool {
public: public:
ChainItemPool() { ChainItemPool() {
@ -356,7 +376,7 @@ public:
static const size_t kBucketSizes[] = { sizeof(nsEventTargetChainItem) }; static const size_t kBucketSizes[] = { sizeof(nsEventTargetChainItem) };
static const PRInt32 kNumBuckets = sizeof(kBucketSizes) / sizeof(size_t); static const PRInt32 kNumBuckets = sizeof(kBucketSizes) / sizeof(size_t);
static const PRInt32 kInitialPoolSize = static const PRInt32 kInitialPoolSize =
NS_SIZE_IN_HEAP(sizeof(nsEventTargetChainItem)) * 128; NS_SIZE_IN_HEAP(sizeof(nsEventTargetChainItem)) * NS_CHAIN_POOL_SIZE;
nsresult rv = sEtciPool->Init("EventTargetChainItem Pool", kBucketSizes, nsresult rv = sEtciPool->Init("EventTargetChainItem Pool", kBucketSizes,
kNumBuckets, kInitialPoolSize); kNumBuckets, kInitialPoolSize);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
@ -374,9 +394,21 @@ public:
if (sEtciPool) { if (sEtciPool) {
--sEtciPoolUsers; --sEtciPoolUsers;
} }
if (!sEtciPoolUsers) {
if (nsEventTargetChainItem::MaxEtciCount() > NS_CHAIN_POOL_SIZE) {
delete sEtciPool;
sEtciPool = nsnull;
nsEventTargetChainItem::ResetMaxEtciCount();
}
}
}
static void Shutdown()
{
if (!sEtciPoolUsers) { if (!sEtciPoolUsers) {
delete sEtciPool; delete sEtciPool;
sEtciPool = nsnull; sEtciPool = nsnull;
nsEventTargetChainItem::ResetMaxEtciCount();
} }
} }
@ -389,6 +421,8 @@ public:
nsFixedSizeAllocator* ChainItemPool::sEtciPool = nsnull; nsFixedSizeAllocator* ChainItemPool::sEtciPool = nsnull;
PRInt32 ChainItemPool::sEtciPoolUsers = 0; PRInt32 ChainItemPool::sEtciPoolUsers = 0;
void NS_ShutdownChainItemPool() { ChainItemPool::Shutdown(); }
/* static */ nsresult /* static */ nsresult
nsEventDispatcher::Dispatch(nsISupports* aTarget, nsEventDispatcher::Dispatch(nsISupports* aTarget,
nsPresContext* aPresContext, nsPresContext* aPresContext,

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

@ -126,6 +126,8 @@ PRBool NS_SVGEnabled();
#include "nsCycleCollector.h" #include "nsCycleCollector.h"
#include "nsJSEnvironment.h" #include "nsJSEnvironment.h"
extern void NS_ShutdownChainItemPool();
static nsrefcnt sLayoutStaticRefcnt; static nsrefcnt sLayoutStaticRefcnt;
nsresult nsresult
@ -361,6 +363,8 @@ nsLayoutStatics::Shutdown()
#endif #endif
nsXMLHttpRequest::ShutdownACCache(); nsXMLHttpRequest::ShutdownACCache();
NS_ShutdownChainItemPool();
} }
void void