Bug 1317954 - Use auto type specifier where aplicable for variable declarations to improve code readability and maintainability in xpcom/.
MozReview-Commit-ID: EZZrYF1W81B
--- a/xpcom/components/nsCategoryManager.cpp
+++ b/xpcom/components/nsCategoryManager.cpp
@@ -108,18 +108,17 @@ BaseStringEnumerator::HasMoreElements(bo
NS_IMETHODIMP
BaseStringEnumerator::GetNext(nsISupports** aResult)
{
if (mSimpleCurItem >= mCount) {
return NS_ERROR_FAILURE;
}
- nsSupportsDependentCString* str =
- new nsSupportsDependentCString(mArray[mSimpleCurItem++]);
+ auto* str = new nsSupportsDependentCString(mArray[mSimpleCurItem++]);
if (!str) {
return NS_ERROR_OUT_OF_MEMORY;
}
*aResult = str;
NS_ADDREF(*aResult);
return NS_OK;
}
@@ -168,17 +167,17 @@ class EntryEnumerator
public:
static EntryEnumerator* Create(nsTHashtable<CategoryLeaf>& aTable);
};
EntryEnumerator*
EntryEnumerator::Create(nsTHashtable<CategoryLeaf>& aTable)
{
- EntryEnumerator* enumObj = new EntryEnumerator();
+ auto* enumObj = new EntryEnumerator();
if (!enumObj) {
return nullptr;
}
enumObj->mArray = new char const* [aTable.Count()];
if (!enumObj->mArray) {
delete enumObj;
return nullptr;
@@ -332,17 +331,17 @@ public:
static CategoryEnumerator* Create(nsClassHashtable<nsDepCharHashKey,
CategoryNode>& aTable);
};
CategoryEnumerator*
CategoryEnumerator::Create(nsClassHashtable<nsDepCharHashKey, CategoryNode>&
aTable)
{
- CategoryEnumerator* enumObj = new CategoryEnumerator();
+ auto* enumObj = new CategoryEnumerator();
if (!enumObj) {
return nullptr;
}
enumObj->mArray = new const char* [aTable.Count()];
if (!enumObj->mArray) {
delete enumObj;
return nullptr;
--- a/xpcom/components/nsComponentManager.cpp
+++ b/xpcom/components/nsComponentManager.cpp
@@ -716,17 +716,17 @@ nsComponentManagerImpl::ManifestComponen
void* place;
PL_ARENA_ALLOCATE(place, &mArena, sizeof(nsCID));
nsID* permanentCID = static_cast<nsID*>(place);
*permanentCID = cid;
PL_ARENA_ALLOCATE(place, &mArena, sizeof(mozilla::Module::CIDEntry));
- mozilla::Module::CIDEntry* e = new (place) mozilla::Module::CIDEntry();
+ auto* e = new (place) mozilla::Module::CIDEntry();
e->cid = permanentCID;
f = new nsFactoryEntry(e, km);
mFactories.Put(cid, f);
}
void
nsComponentManagerImpl::ManifestContract(ManifestProcessingContext& aCx,
@@ -1686,17 +1686,17 @@ nsComponentManagerImpl::EnumerateCIDs(ns
array.AppendObject(wrapper);
}
return NS_NewArrayEnumerator(aEnumerator, array);
}
NS_IMETHODIMP
nsComponentManagerImpl::EnumerateContractIDs(nsISimpleEnumerator** aEnumerator)
{
- nsTArray<nsCString>* array = new nsTArray<nsCString>;
+ auto* array = new nsTArray<nsCString>;
for (auto iter = mContractIDs.Iter(); !iter.Done(); iter.Next()) {
const nsACString& contract = iter.Key();
array->AppendElement(contract);
}
nsCOMPtr<nsIUTF8StringEnumerator> e;
nsresult rv = NS_NewAdoptingUTF8StringEnumerator(getter_AddRefs(e), array);
if (NS_FAILED(rv)) {
@@ -1798,18 +1798,18 @@ nsFactoryEntry::nsFactoryEntry(const moz
{
}
nsFactoryEntry::nsFactoryEntry(const nsCID& aCID, nsIFactory* aFactory)
: mCIDEntry(nullptr)
, mModule(nullptr)
, mFactory(aFactory)
{
- mozilla::Module::CIDEntry* e = new mozilla::Module::CIDEntry();
- nsCID* cid = new nsCID;
+ auto* e = new mozilla::Module::CIDEntry();
+ auto* cid = new nsCID;
*cid = aCID;
e->cid = cid;
mCIDEntry = e;
}
nsFactoryEntry::~nsFactoryEntry()
{
// If this was a RegisterFactory entry, we own the CIDEntry/CID
--- a/xpcom/glue/nsEnumeratorUtils.cpp
+++ b/xpcom/glue/nsEnumeratorUtils.cpp
@@ -274,18 +274,18 @@ NS_NewUnionEnumerator(nsISimpleEnumerato
nsISimpleEnumerator* aSecondEnumerator)
{
*aResult = nullptr;
if (!aFirstEnumerator) {
*aResult = aSecondEnumerator;
} else if (!aSecondEnumerator) {
*aResult = aFirstEnumerator;
} else {
- nsUnionEnumerator* enumer = new nsUnionEnumerator(aFirstEnumerator,
- aSecondEnumerator);
+ auto* enumer = new nsUnionEnumerator(aFirstEnumerator,
+ aSecondEnumerator);
if (!enumer) {
return NS_ERROR_OUT_OF_MEMORY;
}
*aResult = enumer;
}
NS_ADDREF(*aResult);
return NS_OK;
}
--- a/xpcom/glue/nsTArray.cpp
+++ b/xpcom/glue/nsTArray.cpp
@@ -21,16 +21,16 @@ IsTwiceTheRequiredBytesRepresentableAsUi
MOZ_NORETURN MOZ_COLD void
InvalidArrayIndex_CRASH(size_t aIndex, size_t aLength)
{
const size_t CAPACITY = 512;
// Leak the buffer on the heap to make sure that it lives long enough, as
// MOZ_CRASH_ANNOTATE expects the pointer passed to it to live to the end of
// the program.
- char* buffer = new char[CAPACITY];
+ auto* buffer = new char[CAPACITY];
snprintf(buffer, CAPACITY,
"ElementAt(aIndex = %llu, aLength = %llu)",
(long long unsigned) aIndex,
(long long unsigned) aLength);
MOZ_CRASH_ANNOTATE(buffer);
MOZ_REALLY_CRASH();
}
--- a/xpcom/glue/standalone/nsXPCOMGlue.cpp
+++ b/xpcom/glue/standalone/nsXPCOMGlue.cpp
@@ -129,17 +129,17 @@ struct DependentLib
DependentLib* next;
};
static DependentLib* sTop;
static void
AppendDependentLib(LibHandleType aLibHandle)
{
- DependentLib* d = new DependentLib;
+ auto* d = new DependentLib;
if (!d) {
return;
}
d->next = sTop;
d->libHandle = aLibHandle;
sTop = d;
--- a/xpcom/io/nsLocalFileUnix.cpp
+++ b/xpcom/io/nsLocalFileUnix.cpp
@@ -822,17 +822,17 @@ nsLocalFile::CopyToNative(nsIFile* aNewP
return rv;
}
#ifdef DEBUG_blizzard
printf("nsLocalFile::CopyTo() %s -> %s\n", mPath.get(), newPathName.get());
#endif
// actually create the file.
- nsLocalFile* newFile = new nsLocalFile();
+ auto* newFile = new nsLocalFile();
nsCOMPtr<nsIFile> fileRef(newFile); // release on exit
rv = newFile->InitWithNativePath(newPathName);
if (NS_FAILED(rv)) {
return rv;
}
// get the old permissions
@@ -1035,17 +1035,17 @@ nsLocalFile::Remove(bool aRecursive)
return rv;
}
if (isSymLink || !S_ISDIR(mCachedStat.st_mode)) {
return NSRESULT_FOR_RETURN(unlink(mPath.get()));
}
if (aRecursive) {
- nsDirEnumeratorUnix* dir = new nsDirEnumeratorUnix();
+ auto* dir = new nsDirEnumeratorUnix();
nsCOMPtr<nsISimpleEnumerator> dirRef(dir); // release on exit
rv = dir->Init(this, false);
if (NS_FAILED(rv)) {
return rv;
}
--- a/xpcom/tests/gtest/TestCOMPtr.cpp
+++ b/xpcom/tests/gtest/TestCOMPtr.cpp
@@ -97,17 +97,17 @@ IFoo::QueryInterface( const nsIID& aIID,
return status;
}
nsresult
CreateIFoo( void** result )
// a typical factory function (that calls AddRef)
{
- IFoo* foop = new IFoo;
+ auto* foop = new IFoo;
foop->AddRef();
*result = foop;
return NS_OK;
}
void
@@ -185,17 +185,17 @@ IBar::QueryInterface( const nsID& aIID,
}
nsresult
CreateIBar( void** result )
// a typical factory function (that calls AddRef)
{
- IBar* barp = new IBar;
+ auto* barp = new IBar;
barp->AddRef();
*result = barp;
return NS_OK;
}
void
@@ -327,20 +327,20 @@ void Comparison()
}
ASSERT_EQ(IFoo::total_destructions_, 2);
}
void DontAddRef()
{
{
- IFoo* raw_foo1p = new IFoo;
+ auto* raw_foo1p = new IFoo;
raw_foo1p->AddRef();
- IFoo* raw_foo2p = new IFoo;
+ auto* raw_foo2p = new IFoo;
raw_foo2p->AddRef();
nsCOMPtr<IFoo> foo1p( dont_AddRef(raw_foo1p) );
ASSERT_EQ(raw_foo1p, foo1p);
ASSERT_EQ(foo1p->refcount_, (unsigned int)1);
nsCOMPtr<IFoo> foo2p;
foo2p = dont_AddRef(raw_foo2p);
--- a/xpcom/tests/gtest/TestHashtables.cpp
+++ b/xpcom/tests/gtest/TestHashtables.cpp
@@ -241,17 +241,17 @@ IFoo::GetString(nsACString& aString)
aString = mString;
return NS_OK;
}
nsresult
CreateIFoo( IFoo** result )
// a typical factory function (that calls AddRef)
{
- IFoo* foop = new IFoo();
+ auto* foop = new IFoo();
foop->AddRef();
*result = foop;
return NS_OK;
}
} // namespace TestHashtables
@@ -313,17 +313,17 @@ TEST(Hashtables, DataHashtable)
}
TEST(Hashtables, ClassHashtable)
{
// check a class-hashtable
nsClassHashtable<nsCStringHashKey,TestUniChar> EntToUniClass(ENTITY_COUNT);
for (auto& entity : gEntities) {
- TestUniChar* temp = new TestUniChar(entity.mUnicode);
+ auto* temp = new TestUniChar(entity.mUnicode);
EntToUniClass.Put(nsDependentCString(entity.mStr), temp);
}
TestUniChar* myChar;
for (auto& entity : gEntities) {
ASSERT_TRUE(EntToUniClass.Get(nsDependentCString(entity.mStr), &myChar));
}
--- a/xpcom/tests/gtest/TestNsRefPtr.cpp
+++ b/xpcom/tests/gtest/TestNsRefPtr.cpp
@@ -123,17 +123,17 @@ void
Foo::VirtualConstMemberFunction( int aArg1, int* aArgPtr, int& aArgRef ) const
{
}
nsresult
CreateFoo( void** result )
// a typical factory function (that calls AddRef)
{
- Foo* foop = new Foo;
+ auto* foop = new Foo;
foop->AddRef();
*result = foop;
return NS_OK;
}
void
@@ -326,20 +326,20 @@ TEST(nsRefPtr, Equality)
ASSERT_EQ(Foo::total_destructions_, 2);
}
TEST(nsRefPtr, AddRefHelpers)
{
Foo::total_addrefs_ = 0;
{
- Foo* raw_foo1p = new Foo;
+ auto* raw_foo1p = new Foo;
raw_foo1p->AddRef();
- Foo* raw_foo2p = new Foo;
+ auto* raw_foo2p = new Foo;
raw_foo2p->AddRef();
ASSERT_EQ(Foo::total_addrefs_, 2);
RefPtr<Foo> foo1p( dont_AddRef(raw_foo1p) );
ASSERT_EQ(Foo::total_addrefs_, 2);