Bug 1317954 - Converts for(...; ...; ...) loops to use the new range-based loops in C++11 in xpcom/.
MozReview-Commit-ID: 9mKXvXyYa6U
--- a/xpcom/glue/nsID.cpp
+++ b/xpcom/glue/nsID.cpp
@@ -8,19 +8,17 @@
#include "nsMemory.h"
#include "mozilla/Sprintf.h"
void nsID::Clear()
{
m0 = 0;
m1 = 0;
m2 = 0;
- for (int i = 0; i < 8; ++i) {
- m3[i] = 0;
- }
+ memset(m3, 0, sizeof(m3));
}
/**
* Multiplies the_int_var with 16 (0x10) and adds the value of the
* hexadecimal digit the_char. If it fails it returns false from
* the function it's used in.
*/
--- a/xpcom/io/nsLocalFileUnix.cpp
+++ b/xpcom/io/nsLocalFileUnix.cpp
@@ -1552,18 +1552,18 @@ nsLocalFile::IsExecutable(bool* aResult)
}
// Search for any of the set of executable extensions.
static const char* const executableExts[] = {
"air", // Adobe AIR installer
"jar" // java application bundle
};
nsDependentSubstring ext = Substring(path, dotIdx + 1);
- for (size_t i = 0; i < ArrayLength(executableExts); i++) {
- if (ext.EqualsASCII(executableExts[i])) {
+ for (auto executableExt : executableExts) {
+ if (ext.EqualsASCII(executableExt)) {
// Found a match. Set result and quit.
*aResult = true;
return NS_OK;
}
}
}
// On OS X, then query Launch Services.
--- a/xpcom/tests/gtest/TestHashtables.cpp
+++ b/xpcom/tests/gtest/TestHashtables.cpp
@@ -279,24 +279,24 @@ TEST(Hashtable, THashtable)
ASSERT_EQ(count, uint32_t(0));
}
TEST(Hashtables, DataHashtable)
{
// check a data-hashtable
nsDataHashtable<nsUint32HashKey,const char*> UniToEntity(ENTITY_COUNT);
- for (uint32_t i = 0; i < ENTITY_COUNT; ++i) {
- UniToEntity.Put(gEntities[i].mUnicode, gEntities[i].mStr);
+ for (auto& entity : gEntities) {
+ UniToEntity.Put(entity.mUnicode, entity.mStr);
}
const char* str;
- for (uint32_t i = 0; i < ENTITY_COUNT; ++i) {
- ASSERT_TRUE(UniToEntity.Get(gEntities[i].mUnicode, &str));
+ for (auto& entity : gEntities) {
+ ASSERT_TRUE(UniToEntity.Get(entity.mUnicode, &str));
}
ASSERT_FALSE(UniToEntity.Get(99446, &str));
uint32_t count = 0;
for (auto iter = UniToEntity.Iter(); !iter.Done(); iter.Next()) {
count++;
}
@@ -312,25 +312,25 @@ TEST(Hashtables, DataHashtable)
ASSERT_EQ(count, uint32_t(0));
}
TEST(Hashtables, ClassHashtable)
{
// check a class-hashtable
nsClassHashtable<nsCStringHashKey,TestUniChar> EntToUniClass(ENTITY_COUNT);
- for (uint32_t i = 0; i < ENTITY_COUNT; ++i) {
- TestUniChar* temp = new TestUniChar(gEntities[i].mUnicode);
- EntToUniClass.Put(nsDependentCString(gEntities[i].mStr), temp);
+ for (auto& entity : gEntities) {
+ TestUniChar* temp = new TestUniChar(entity.mUnicode);
+ EntToUniClass.Put(nsDependentCString(entity.mStr), temp);
}
TestUniChar* myChar;
- for (uint32_t i = 0; i < ENTITY_COUNT; ++i) {
- ASSERT_TRUE(EntToUniClass.Get(nsDependentCString(gEntities[i].mStr), &myChar));
+ for (auto& entity : gEntities) {
+ ASSERT_TRUE(EntToUniClass.Get(nsDependentCString(entity.mStr), &myChar));
}
ASSERT_FALSE(EntToUniClass.Get(NS_LITERAL_CSTRING("xxxx"), &myChar));
uint32_t count = 0;
for (auto iter = EntToUniClass.Iter(); !iter.Done(); iter.Next()) {
count++;
}
@@ -391,27 +391,27 @@ TEST(Hashtables, DataHashtableWithInterf
ASSERT_EQ(count, uint32_t(0));
}
TEST(Hashtables, InterfaceHashtable)
{
// check an interface-hashtable with an uint32_t key
nsInterfaceHashtable<nsUint32HashKey,IFoo> UniToEntClass2(ENTITY_COUNT);
- for (uint32_t i = 0; i < ENTITY_COUNT; ++i) {
+ for (auto& entity : gEntities) {
nsCOMPtr<IFoo> foo;
CreateIFoo(getter_AddRefs(foo));
- foo->SetString(nsDependentCString(gEntities[i].mStr));
+ foo->SetString(nsDependentCString(entity.mStr));
- UniToEntClass2.Put(gEntities[i].mUnicode, foo);
+ UniToEntClass2.Put(entity.mUnicode, foo);
}
- for (uint32_t i = 0; i < ENTITY_COUNT; ++i) {
+ for (auto& entity : gEntities) {
nsCOMPtr<IFoo> myEnt;
- ASSERT_TRUE(UniToEntClass2.Get(gEntities[i].mUnicode, getter_AddRefs(myEnt)));
+ ASSERT_TRUE(UniToEntClass2.Get(entity.mUnicode, getter_AddRefs(myEnt)));
nsAutoCString myEntStr;
myEnt->GetString(myEntStr);
}
nsCOMPtr<IFoo> myEnt;
ASSERT_FALSE(UniToEntClass2.Get(9462, getter_AddRefs(myEnt)));