Bug 859817 - Make NS_NewAtom return already_AddRefed; r=bz

This commit is contained in:
Aryeh Gregor
2013-04-22 14:13:22 +03:00
parent 563acc033a
commit 03b4600974
15 changed files with 47 additions and 51 deletions

View File

@@ -616,23 +616,22 @@ RegisterStaticAtoms(const nsStaticAtom* aAtoms, uint32_t aAtomCount)
return NS_OK;
}
nsIAtom*
already_AddRefed<nsIAtom>
NS_NewAtom(const char* aUTF8String)
{
return NS_NewAtom(nsDependentCString(aUTF8String));
}
nsIAtom*
already_AddRefed<nsIAtom>
NS_NewAtom(const nsACString& aUTF8String)
{
AtomTableEntry *he = GetAtomHashEntry(aUTF8String.Data(),
aUTF8String.Length());
if (he->mAtom) {
nsIAtom* atom;
NS_ADDREF(atom = he->mAtom);
nsCOMPtr<nsIAtom> atom = he->mAtom;
return atom;
return atom.forget();
}
// This results in an extra addref/release of the nsStringBuffer.
@@ -640,38 +639,35 @@ NS_NewAtom(const nsACString& aUTF8String)
// Actually, now there is, sort of: ForgetSharedBuffer.
nsString str;
CopyUTF8toUTF16(aUTF8String, str);
AtomImpl* atom = new AtomImpl(str, he->keyHash);
nsRefPtr<AtomImpl> atom = new AtomImpl(str, he->keyHash);
he->mAtom = atom;
NS_ADDREF(atom);
return atom;
return atom.forget();
}
nsIAtom*
already_AddRefed<nsIAtom>
NS_NewAtom(const PRUnichar* aUTF16String)
{
return NS_NewAtom(nsDependentString(aUTF16String));
}
nsIAtom*
already_AddRefed<nsIAtom>
NS_NewAtom(const nsAString& aUTF16String)
{
AtomTableEntry *he = GetAtomHashEntry(aUTF16String.Data(),
aUTF16String.Length());
if (he->mAtom) {
nsIAtom* atom;
NS_ADDREF(atom = he->mAtom);
nsCOMPtr<nsIAtom> atom = he->mAtom;
return atom;
return atom.forget();
}
AtomImpl* atom = new AtomImpl(aUTF16String, he->keyHash);
nsRefPtr<AtomImpl> atom = new AtomImpl(aUTF16String, he->keyHash);
he->mAtom = atom;
NS_ADDREF(atom);
return atom;
return atom.forget();
}
nsIAtom*