Improve box object hashtable storage b=326931 r=jst sr=bz

This commit is contained in:
neil%parkwaycc.co.uk 2006-04-26 12:42:49 +00:00
Родитель 497b79ea18
Коммит de6fc340e9
6 изменённых файлов: 34 добавлений и 48 удалений

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

@ -91,8 +91,8 @@ class nsIDocumentObserver;
// IID for the nsIDocument interface
#define NS_IDOCUMENT_IID \
{ 0x3b3cb52f, 0xf604, 0x48d5, \
{ 0xb5, 0x70, 0xf3, 0x25, 0xbb, 0x0a, 0x7a, 0x22 } }
{ 0x726ce58e, 0x13ab, 0x4c91, \
{ 0x80, 0x45, 0xa8, 0x7b, 0xfe, 0xd5, 0xfe, 0xcd } }
// Flag for AddStyleSheet().
@ -899,6 +899,13 @@ public:
virtual void CopyUserData(const nsINode *aObject,
nsIDocument *aDestination) = 0;
/**
* Resets and removes a box object from the document's box object cache
*
* @param aElement canonical nsIContent pointer of the box object's element
*/
virtual void ClearBoxObjectFor(nsIContent *aContent) = 0;
protected:
~nsIDocument()
{

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

@ -106,8 +106,6 @@
#include "nsPIDOMWindow.h"
#include "nsIDOMElement.h"
#include "nsIBoxObject.h"
#include "nsPIBoxObject.h"
#include "nsXULAtoms.h"
// for radio group stuff
@ -3228,21 +3226,18 @@ nsDocument::GetBoxObjectFor(nsIDOMElement* aElement, nsIBoxObject** aResult)
NS_ENSURE_TRUE(content->GetCurrentDoc() == this,
NS_ERROR_DOM_WRONG_DOCUMENT_ERR);
nsresult rv;
*aResult = nsnull;
if (!mBoxObjectTable) {
mBoxObjectTable = new nsSupportsHashtable;
mBoxObjectTable = new nsInterfaceHashtable<nsISupportsHashKey, nsPIBoxObject>;
if (mBoxObjectTable) {
mBoxObjectTable->Init(12);
}
} else {
nsISupportsKey key(aElement);
nsCOMPtr<nsISupports> supports = dont_AddRef(mBoxObjectTable->Get(&key));
nsCOMPtr<nsIBoxObject> boxObject(do_QueryInterface(supports));
if (boxObject) {
*aResult = boxObject;
// Want to use Get(content, aResult); but it's the wrong type
*aResult = mBoxObjectTable->GetWeak(content);
if (*aResult) {
NS_ADDREF(*aResult);
return NS_OK;
}
}
@ -3276,14 +3271,15 @@ nsDocument::GetBoxObjectFor(nsIDOMElement* aElement, nsIBoxObject** aResult)
}
contractID += ";1";
nsCOMPtr<nsIBoxObject> boxObject(do_CreateInstance(contractID.get()));
nsCOMPtr<nsPIBoxObject> boxObject(do_CreateInstance(contractID.get()));
if (!boxObject)
return NS_ERROR_FAILURE;
nsCOMPtr<nsPIBoxObject> privateBox(do_QueryInterface(boxObject));
privateBox->Init(content);
boxObject->Init(content);
SetBoxObjectFor(aElement, boxObject);
if (mBoxObjectTable) {
mBoxObjectTable->Put(content, boxObject.get());
}
*aResult = boxObject;
NS_ADDREF(*aResult);
@ -3291,29 +3287,16 @@ nsDocument::GetBoxObjectFor(nsIDOMElement* aElement, nsIBoxObject** aResult)
return NS_OK;
}
NS_IMETHODIMP
nsDocument::SetBoxObjectFor(nsIDOMElement* aElement, nsIBoxObject* aBoxObject)
void
nsDocument::ClearBoxObjectFor(nsIContent* aContent)
{
if (!mBoxObjectTable) {
if (!aBoxObject)
return NS_OK;
mBoxObjectTable = new nsSupportsHashtable(12);
}
nsISupportsKey key(aElement);
if (aBoxObject) {
mBoxObjectTable->Put(&key, aBoxObject);
} else {
nsCOMPtr<nsISupports> supp;
mBoxObjectTable->Remove(&key, getter_AddRefs(supp));
nsCOMPtr<nsPIBoxObject> boxObject(do_QueryInterface(supp));
if (mBoxObjectTable) {
nsPIBoxObject *boxObject = mBoxObjectTable->GetWeak(aContent);
if (boxObject) {
boxObject->Clear();
mBoxObjectTable->Remove(aContent);
}
}
return NS_OK;
}
struct DirTable {

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

@ -77,6 +77,9 @@
#include "nsIDOM3DocumentEvent.h"
#include "nsCOMArray.h"
#include "nsHashtable.h"
#include "nsInterfaceHashtable.h"
#include "nsIBoxObject.h"
#include "nsPIBoxObject.h"
#include "nsIScriptObjectPrincipal.h"
#include "nsIURI.h"
#include "nsScriptLoader.h"
@ -673,6 +676,7 @@ public:
nsIDOMNode *aDest);
NS_HIDDEN_(void) CopyUserData(const nsINode *aObject,
nsIDocument *aDestination);
NS_HIDDEN_(void) ClearBoxObjectFor(nsIContent* aContent);
protected:
@ -784,7 +788,7 @@ protected:
PRUint8 mDefaultElementType;
nsSupportsHashtable* mBoxObjectTable;
nsInterfaceHashtable<nsISupportsHashKey, nsPIBoxObject> *mBoxObjectTable;
// The channel that got passed to StartDocumentLoad(), if any
nsCOMPtr<nsIChannel> mChannel;

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

@ -1850,12 +1850,7 @@ nsGenericElement::UnbindFromTree(PRBool aDeep, PRBool aNullParent)
document->ForgetLink(this);
}
nsCOMPtr<nsIDOMElement> domElement = do_QueryInterface(this);
if (domElement) {
nsCOMPtr<nsIDOMNSDocument> nsDoc = do_QueryInterface(document);
nsDoc->SetBoxObjectFor(domElement, nsnull);
}
document->ClearBoxObjectFor(this);
}
// Unset things in the reverse order from how we set them in BindToTree

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

@ -937,8 +937,7 @@ nsXULElement::UnbindFromTree(PRBool aDeep, PRBool aNullParent)
// anonymous content that the document is changing.
document->BindingManager()->ChangeDocumentFor(this, document, nsnull);
nsCOMPtr<nsIDOMNSDocument> nsDoc(do_QueryInterface(document));
nsDoc->SetBoxObjectFor(this, nsnull);
document->ClearBoxObjectFor(this);
}
// mControllers can own objects that are implemented

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

@ -43,7 +43,7 @@ interface nsIBoxObject;
interface nsIDOMLocation;
[scriptable, uuid(a6cf90cd-15b3-11d2-932e-00805f8add32)]
[scriptable, uuid(170763c7-c94e-4db9-98be-e69ac3a02a41)]
interface nsIDOMNSDocument : nsISupports
{
readonly attribute DOMString characterSet;
@ -58,6 +58,4 @@ interface nsIDOMNSDocument : nsISupports
readonly attribute DOMString referrer;
nsIBoxObject getBoxObjectFor(in nsIDOMElement elt);
void setBoxObjectFor(in nsIDOMElement elt,
in nsIBoxObject boxObject);
};