Bug 558795 - speed up nsEventTargetChainItem (de)allocation, r=jst

This commit is contained in:
Olli Pettay 2010-04-15 12:38:32 +03:00
Родитель 4ce178ae7c
Коммит f25a8a3827
1 изменённых файлов: 18 добавлений и 3 удалений

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

@ -54,6 +54,8 @@
#define NS_TARGET_CHAIN_WANTS_WILL_HANDLE_EVENT (1 << 1)
#define NS_TARGET_CHAIN_MAY_HAVE_MANAGER (1 << 2)
static nsEventTargetChainItem* gCachedETCI = nsnull;
// nsEventTargetChainItem represents a single item in the event target chain.
class nsEventTargetChainItem
{
@ -66,7 +68,13 @@ public:
nsPIDOMEventTarget* aTarget,
nsEventTargetChainItem* aChild = nsnull)
{
void* place = aAllocator->Alloc(sizeof(nsEventTargetChainItem));
void* place = nsnull;
if (gCachedETCI) {
place = gCachedETCI;
gCachedETCI = gCachedETCI->mNext;
} else {
place = aAllocator->Alloc(sizeof(nsEventTargetChainItem));
}
return place
? ::new (place) nsEventTargetChainItem(aTarget, aChild)
: nsnull;
@ -84,7 +92,8 @@ public:
while (item) {
nsEventTargetChainItem* parent = item->mParent;
item->~nsEventTargetChainItem();
aAllocator->Free(item, sizeof(nsEventTargetChainItem));
item->mNext = gCachedETCI;
gCachedETCI = item;
--sCurrentEtciCount;
item = parent;
}
@ -220,7 +229,11 @@ public:
nsCOMPtr<nsPIDOMEventTarget> mTarget;
nsEventTargetChainItem* mChild;
union {
nsEventTargetChainItem* mParent;
// This is used only when caching ETCI objects.
nsEventTargetChainItem* mNext;
};
PRUint16 mFlags;
PRUint16 mItemFlags;
nsCOMPtr<nsISupports> mItemData;
@ -414,6 +427,7 @@ public:
}
if (!sEtciPoolUsers) {
if (nsEventTargetChainItem::MaxEtciCount() > NS_CHAIN_POOL_SIZE) {
gCachedETCI = nsnull;
delete sEtciPool;
sEtciPool = nsnull;
nsEventTargetChainItem::ResetMaxEtciCount();
@ -424,6 +438,7 @@ public:
static void Shutdown()
{
if (!sEtciPoolUsers) {
gCachedETCI = nsnull;
delete sEtciPool;
sEtciPool = nsnull;
nsEventTargetChainItem::ResetMaxEtciCount();