Speed up mapping HTML tag enums to atoms by using an array of static atoms, indexed by enum value. This avoids a UTF16 to UTF8 conversion and atom table lookup for each tag. Add a CString version of nsINodeInfoManager::GetNodeInfo(), convert literal string callers to use that version, and remove some unused variants of GetNodeInfo(). Bug 223595, r=axel@pike.org, sr=jst.
git-svn-id: svn://10.0.0.236/trunk@148857 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -41,6 +41,8 @@
|
||||
|
||||
#include "nsAString.h"
|
||||
|
||||
class nsIAtom;
|
||||
|
||||
/*
|
||||
Declare the enum list using the magic of preprocessing
|
||||
enum values are "eHTMLTag_foo" (where foo is the tag)
|
||||
@@ -73,6 +75,7 @@ public:
|
||||
static nsHTMLTag LookupTag(const nsAString& aTagName);
|
||||
static nsHTMLTag CaseSensitiveLookupTag(const PRUnichar* aTagName);
|
||||
static const PRUnichar *GetStringValue(nsHTMLTag aEnum);
|
||||
static nsIAtom *GetAtom(nsHTMLTag aEnum);
|
||||
};
|
||||
|
||||
#define eHTMLTags nsHTMLTag
|
||||
|
||||
@@ -84,6 +84,7 @@ class CToken;
|
||||
class nsIURI;
|
||||
class nsIContentSink;
|
||||
class CParserContext;
|
||||
class nsIAtom;
|
||||
|
||||
class nsIDTD : public nsISupports
|
||||
{
|
||||
@@ -220,6 +221,8 @@ public:
|
||||
|
||||
NS_IMETHOD_(const PRUnichar *) IntTagToStringTag(PRInt32 aIntTag) const = 0;
|
||||
|
||||
NS_IMETHOD_(nsIAtom *) IntTagToAtom(PRInt32 aIntTag) const = 0;
|
||||
|
||||
NS_IMETHOD_(PRBool) IsBlockElement(PRInt32 aTagID,
|
||||
PRInt32 aParentID) const = 0;
|
||||
|
||||
@@ -244,6 +247,7 @@ public:
|
||||
NS_IMETHOD_(PRInt32) GetType(); \
|
||||
NS_IMETHOD StringTagToIntTag(const nsAString &aTag, PRInt32* aIntTag) const ;\
|
||||
NS_IMETHOD_(const PRUnichar *) IntTagToStringTag(PRInt32 aIntTag) const ;\
|
||||
NS_IMETHOD_(nsIAtom *) IntTagToAtom(PRInt32 aIntTag) const;\
|
||||
NS_IMETHOD_(PRBool) IsBlockElement(PRInt32 aTagID,PRInt32 aParentID) const;\
|
||||
NS_IMETHOD_(PRBool) IsInlineElement(PRInt32 aTagID,PRInt32 aParentID) const;
|
||||
#endif /* nsIDTD_h___ */
|
||||
|
||||
@@ -2585,6 +2585,17 @@ CNavDTD::IntTagToStringTag(PRInt32 aIntTag) const
|
||||
return str_ptr;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(nsIAtom *)
|
||||
CNavDTD::IntTagToAtom(PRInt32 aIntTag) const
|
||||
{
|
||||
nsIAtom *atom = nsHTMLTags::GetAtom((nsHTMLTag)aIntTag);
|
||||
|
||||
NS_ASSERTION(atom, "Bad tag enum passed to CNavDTD::IntTagToAtom()"
|
||||
"!!");
|
||||
|
||||
return atom;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called to determine whether or not
|
||||
* the given childtag is a block element.
|
||||
|
||||
@@ -906,6 +906,17 @@ COtherDTD::IntTagToStringTag(PRInt32 aIntTag) const
|
||||
return str_ptr;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(nsIAtom *)
|
||||
COtherDTD::IntTagToAtom(PRInt32 aIntTag) const
|
||||
{
|
||||
nsIAtom *atom = nsHTMLTags::GetAtom((nsHTMLTag)aIntTag);
|
||||
|
||||
NS_ASSERTION(atom, "Bad tag enum passed to COtherDTD::IntTagToAtom()"
|
||||
"!!");
|
||||
|
||||
return atom;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called to determine whether or not
|
||||
* the given childtag is a block element.
|
||||
|
||||
@@ -1196,4 +1196,10 @@ nsExpatDriver::IntTagToStringTag(PRInt32 aIntTag) const
|
||||
return 0;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(nsIAtom *)
|
||||
nsExpatDriver::IntTagToAtom(PRInt32 aIntTag) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include "nsReadableUtils.h"
|
||||
#include "plhash.h"
|
||||
#include "nsString.h"
|
||||
#include "nsStaticAtom.h"
|
||||
|
||||
// C++ sucks! There's no way to do this with a macro, at least not
|
||||
// that I know, if you know how to do this with a macro then please do
|
||||
@@ -275,19 +276,17 @@ static const PRUnichar* const kTagUnicodeTable[] = {
|
||||
#include "nsHTMLTagList.h"
|
||||
};
|
||||
#undef HTML_TAG
|
||||
#undef HTML_OTHER
|
||||
|
||||
// static array of tag atoms
|
||||
static nsIAtom* kTagAtomTable[eHTMLTag_userdefined - 1];
|
||||
|
||||
#ifdef DEBUG
|
||||
// static array of ASCII tag names for debugging purposes
|
||||
#define HTML_TAG(_tag, _classname) #_tag,
|
||||
#define HTML_OTHER(_tag, _classname)
|
||||
static const char* const kTagASCIIDebugTable[] = {
|
||||
// static array of tag StaticAtom structs
|
||||
#define HTML_TAG(_tag, _classname) { #_tag, &kTagAtomTable[eHTMLTag_##_tag - 1] },
|
||||
static const nsStaticAtom kTagAtoms_info[] = {
|
||||
#include "nsHTMLTagList.h"
|
||||
};
|
||||
#undef HTML_TAG
|
||||
#undef HTML_OTHER
|
||||
#endif
|
||||
|
||||
static PRInt32 gTableRefCount;
|
||||
static PLHashTable* gTagTable;
|
||||
@@ -345,12 +344,15 @@ nsHTMLTags::AddRefTable(void)
|
||||
NS_ASSERTION(sMaxTagNameLength == NS_HTMLTAG_NAME_MAX_LENGTH,
|
||||
"NS_HTMLTAG_NAME_MAX_LENGTH not set correctly!");
|
||||
|
||||
// Fill in our static atom pointers
|
||||
NS_RegisterStaticAtoms(kTagAtoms_info, NS_ARRAY_LENGTH(kTagAtoms_info));
|
||||
|
||||
#ifdef DEBUG
|
||||
{
|
||||
// let's verify that all names in the the table are lowercase...
|
||||
for (i = 0; i < NS_HTML_TAG_MAX; ++i) {
|
||||
nsCAutoString temp1(kTagASCIIDebugTable[i]);
|
||||
nsCAutoString temp2(kTagASCIIDebugTable[i]);
|
||||
nsCAutoString temp1(kTagAtoms_info[i].mString);
|
||||
nsCAutoString temp2(kTagAtoms_info[i].mString);
|
||||
ToLowerCase(temp1);
|
||||
NS_ASSERTION(temp1.Equals(temp2), "upper case char in table");
|
||||
}
|
||||
@@ -359,7 +361,7 @@ nsHTMLTags::AddRefTable(void)
|
||||
// correct.
|
||||
for (i = 0; i < NS_HTML_TAG_MAX; ++i) {
|
||||
nsAutoString temp1(kTagUnicodeTable[i]);
|
||||
nsAutoString temp2; temp2.AssignWithConversion(kTagASCIIDebugTable[i]);
|
||||
nsAutoString temp2; temp2.AssignWithConversion(kTagAtoms_info[i].mString);
|
||||
NS_ASSERTION(temp1.Equals(temp2), "Bad unicode tag name!");
|
||||
}
|
||||
}
|
||||
@@ -473,6 +475,17 @@ nsHTMLTags::GetStringValue(nsHTMLTag aEnum)
|
||||
return kTagUnicodeTable[aEnum - 1];
|
||||
}
|
||||
|
||||
// static
|
||||
nsIAtom *
|
||||
nsHTMLTags::GetAtom(nsHTMLTag aEnum)
|
||||
{
|
||||
if (aEnum <= eHTMLTag_unknown || aEnum > NS_HTML_TAG_MAX) {
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
return kTagAtomTable[aEnum - 1];
|
||||
}
|
||||
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
|
||||
|
||||
@@ -903,6 +903,17 @@ CViewSourceHTML::IntTagToStringTag(PRInt32 aIntTag) const
|
||||
return str_ptr;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(nsIAtom *)
|
||||
CViewSourceHTML::IntTagToAtom(PRInt32 aIntTag) const
|
||||
{
|
||||
nsIAtom *atom = nsHTMLTags::GetAtom((nsHTMLTag)aIntTag);
|
||||
|
||||
NS_ASSERTION(atom, "Bad tag enum passed to COtherDTD::IntTagToAtom()"
|
||||
"!!");
|
||||
|
||||
return atom;
|
||||
}
|
||||
|
||||
PRBool CViewSourceHTML::IsBlockElement(PRInt32 aTagID,PRInt32 aParentID) const {
|
||||
PRBool result=PR_FALSE;
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user