зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1292278 - Zero-index the namespace manager URIs. r=bz
The current setup here tries to "save" an entry in the list by checking for the "None" namespace everywhere and special-casing it. We can simplify this a lot by just adding the empty atom to the beginning of the array, which is the value that servo uses to represent "namespace none" anyway.
This commit is contained in:
Родитель
0aa1f8a13a
Коммит
cbb507cc3e
|
@ -66,6 +66,8 @@ bool nsNameSpaceManager::Init()
|
|||
|
||||
|
||||
// Need to be ordered according to ID.
|
||||
MOZ_ASSERT(mURIArray.IsEmpty());
|
||||
REGISTER_NAMESPACE(nsGkAtoms::empty, kNameSpaceID_None);
|
||||
REGISTER_NAMESPACE(nsGkAtoms::nsuri_xmlns, kNameSpaceID_XMLNS);
|
||||
REGISTER_NAMESPACE(nsGkAtoms::nsuri_xml, kNameSpaceID_XML);
|
||||
REGISTER_NAMESPACE(nsGkAtoms::nsuri_xhtml, kNameSpaceID_XHTML);
|
||||
|
@ -97,7 +99,7 @@ nsNameSpaceManager::RegisterNameSpace(const nsAString& aURI,
|
|||
nsCOMPtr<nsIAtom> atom = NS_Atomize(aURI);
|
||||
nsresult rv = NS_OK;
|
||||
if (!mURIToIDTable.Get(atom, &aNameSpaceID)) {
|
||||
aNameSpaceID = mURIArray.Length() + 1; // id is index + 1
|
||||
aNameSpaceID = mURIArray.Length();
|
||||
|
||||
rv = AddNameSpace(atom.forget(), aNameSpaceID);
|
||||
if (NS_FAILED(rv)) {
|
||||
|
@ -114,15 +116,16 @@ nsresult
|
|||
nsNameSpaceManager::GetNameSpaceURI(int32_t aNameSpaceID, nsAString& aURI)
|
||||
{
|
||||
NS_PRECONDITION(aNameSpaceID >= 0, "Bogus namespace ID");
|
||||
|
||||
int32_t index = aNameSpaceID - 1; // id is index + 1
|
||||
if (index < 0 || index >= int32_t(mURIArray.Length())) {
|
||||
|
||||
// We have historically treated GetNameSpaceURI calls for kNameSpaceID_None
|
||||
// as erroneous.
|
||||
if (aNameSpaceID <= 0 || aNameSpaceID >= int32_t(mURIArray.Length())) {
|
||||
aURI.Truncate();
|
||||
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
|
||||
mURIArray.ElementAt(index)->ToString(aURI);
|
||||
mURIArray.ElementAt(aNameSpaceID)->ToString(aURI);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -224,10 +227,8 @@ nsresult nsNameSpaceManager::AddNameSpace(already_AddRefed<nsIAtom> aURI,
|
|||
// We've wrapped... Can't do anything else here; just bail.
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
NS_ASSERTION(aNameSpaceID - 1 == (int32_t) mURIArray.Length(),
|
||||
"BAD! AddNameSpace not called in right order!");
|
||||
|
||||
MOZ_ASSERT(aNameSpaceID == (int32_t) mURIArray.Length());
|
||||
mURIArray.AppendElement(uri.forget());
|
||||
mURIToIDTable.Put(mURIArray.LastElement(), aNameSpaceID);
|
||||
|
||||
|
@ -244,9 +245,7 @@ nsNameSpaceManager::AddDisabledNameSpace(already_AddRefed<nsIAtom> aURI,
|
|||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
NS_ASSERTION(aNameSpaceID - 1 == (int32_t) mURIArray.Length(),
|
||||
"BAD! AddDisabledNameSpace not called in right order!");
|
||||
|
||||
MOZ_ASSERT(aNameSpaceID == (int32_t) mURIArray.Length());
|
||||
mURIArray.AppendElement(uri.forget());
|
||||
mDisabledURIToIDTable.Put(mURIArray.LastElement(), aNameSpaceID);
|
||||
|
||||
|
|
|
@ -42,9 +42,19 @@ public:
|
|||
|
||||
virtual nsresult GetNameSpaceURI(int32_t aNameSpaceID, nsAString& aURI);
|
||||
|
||||
// Returns the atom for the namespace URI associated with the given ID. The
|
||||
// ID must be within range and not be kNameSpaceID_None (i.e. zero);
|
||||
nsIAtom* NameSpaceURIAtom(int32_t aNameSpaceID) {
|
||||
MOZ_ASSERT(aNameSpaceID > 0 && (int64_t) aNameSpaceID <= (int64_t) mURIArray.Length());
|
||||
return mURIArray.ElementAt(aNameSpaceID - 1); // id is index + 1
|
||||
MOZ_ASSERT(aNameSpaceID > 0);
|
||||
return NameSpaceURIAtomForServo(aNameSpaceID);
|
||||
}
|
||||
|
||||
// NB: This function should only be called by Servo code (and the above
|
||||
// accessor), which uses the empty atom to represent kNameSpaceID_None.
|
||||
nsIAtom* NameSpaceURIAtomForServo(int32_t aNameSpaceID) {
|
||||
MOZ_ASSERT(aNameSpaceID >= 0);
|
||||
MOZ_ASSERT((int64_t) aNameSpaceID < (int64_t) mURIArray.Length());
|
||||
return mURIArray.ElementAt(aNameSpaceID);
|
||||
}
|
||||
|
||||
int32_t GetNameSpaceID(const nsAString& aURI,
|
||||
|
|
|
@ -155,7 +155,7 @@ nsIAtom*
|
|||
Gecko_Namespace(RawGeckoElement* aElement)
|
||||
{
|
||||
int32_t id = aElement->NodeInfo()->NamespaceID();
|
||||
return nsContentUtils::NameSpaceManager()->NameSpaceURIAtom(id);
|
||||
return nsContentUtils::NameSpaceManager()->NameSpaceURIAtomForServo(id);
|
||||
}
|
||||
|
||||
nsIAtom*
|
||||
|
|
Загрузка…
Ссылка в новой задаче