Bug 1318282 - Converts for(...; ...; ...) loops to use the new range-based loops in C++11 in storage/. draft
authorAndi-Bogdan Postelnicu <bpostelnicu@mozilla.com>
Thu, 17 Nov 2016 12:33:18 +0200
changeset 442289 190baa129d4472e0076f9d9fc2612bc6e4247f35
parent 442068 0534254e9a40b4bade2577c631fe4cfa0b5db41d
child 442290 176e31e5ba552a488b0bdb65e25a66609065a4cd
push id36664
push userbmo:bpostelnicu@mozilla.com
push dateTue, 22 Nov 2016 08:18:07 +0000
bugs1318282
milestone53.0a1
Bug 1318282 - Converts for(...; ...; ...) loops to use the new range-based loops in C++11 in storage/. MozReview-Commit-ID: HuudUDUcQYu
storage/mozStorageConnection.cpp
storage/test/test_mutex.cpp
--- a/storage/mozStorageConnection.cpp
+++ b/storage/mozStorageConnection.cpp
@@ -1414,25 +1414,25 @@ Connection::initializeClone(Connection* 
     "cache_size",
     "temp_store",
     "foreign_keys",
     "journal_size_limit",
     "synchronous",
     "wal_autocheckpoint",
     "busy_timeout"
   };
-  for (uint32_t i = 0; i < ArrayLength(pragmas); ++i) {
+  for (auto& pragma : pragmas) {
     // Read-only connections just need cache_size and temp_store pragmas.
-    if (aReadOnly && ::strcmp(pragmas[i], "cache_size") != 0 &&
-                     ::strcmp(pragmas[i], "temp_store") != 0) {
+    if (aReadOnly && ::strcmp(pragma, "cache_size") != 0 &&
+                     ::strcmp(pragma, "temp_store") != 0) {
       continue;
     }
 
     nsAutoCString pragmaQuery("PRAGMA ");
-    pragmaQuery.Append(pragmas[i]);
+    pragmaQuery.Append(pragma);
     nsCOMPtr<mozIStorageStatement> stmt;
     rv = CreateStatement(pragmaQuery, getter_AddRefs(stmt));
     MOZ_ASSERT(NS_SUCCEEDED(rv));
     bool hasResult = false;
     if (stmt && NS_SUCCEEDED(stmt->ExecuteStep(&hasResult)) && hasResult) {
       pragmaQuery.AppendLiteral(" = ");
       pragmaQuery.AppendInt(stmt->AsInt32(0));
       rv = aClone->ExecuteSimpleSQL(pragmaQuery);
@@ -1976,18 +1976,18 @@ Connection::SetGrowthIncrement(int32_t a
   return NS_OK;
 }
 
 NS_IMETHODIMP
 Connection::EnableModule(const nsACString& aModuleName)
 {
   if (!mDBConn) return NS_ERROR_NOT_INITIALIZED;
 
-  for (size_t i = 0; i < ArrayLength(gModules); i++) {
-    struct Module* m = &gModules[i];
+  for (auto& gModule : gModules) {
+    struct Module* m = &gModule;
     if (aModuleName.Equals(m->name)) {
       int srv = m->registerFunc(mDBConn, m->name);
       if (srv != SQLITE_OK)
         return convertResultCode(srv);
 
       return NS_OK;
     }
   }
--- a/storage/test/test_mutex.cpp
+++ b/storage/test/test_mutex.cpp
@@ -17,21 +17,21 @@ using namespace mozilla::storage;
 
 void
 test_AutoLock()
 {
   int lockTypes[] = {
     SQLITE_MUTEX_FAST,
     SQLITE_MUTEX_RECURSIVE,
   };
-  for (size_t i = 0; i < ArrayLength(lockTypes); i++) {
+  for (int lockType : lockTypes) {
     // Get our test mutex (we have to allocate a SQLite mutex of the right type
     // too!).
     SQLiteMutex mutex("TestMutex");
-    sqlite3_mutex *inner = sqlite3_mutex_alloc(lockTypes[i]);
+    sqlite3_mutex *inner = sqlite3_mutex_alloc(lockType);
     do_check_true(inner);
     mutex.initWithMutex(inner);
 
     // And test that our automatic locking wrapper works as expected.
     mutex.assertNotCurrentThreadOwns();
     {
       SQLiteMutexAutoLock lockedScope(mutex);
       mutex.assertCurrentThreadOwns();
@@ -45,21 +45,21 @@ test_AutoLock()
 
 void
 test_AutoUnlock()
 {
   int lockTypes[] = {
     SQLITE_MUTEX_FAST,
     SQLITE_MUTEX_RECURSIVE,
   };
-  for (size_t i = 0; i < ArrayLength(lockTypes); i++) {
+  for (int lockType : lockTypes) {
     // Get our test mutex (we have to allocate a SQLite mutex of the right type
     // too!).
     SQLiteMutex mutex("TestMutex");
-    sqlite3_mutex *inner = sqlite3_mutex_alloc(lockTypes[i]);
+    sqlite3_mutex *inner = sqlite3_mutex_alloc(lockType);
     do_check_true(inner);
     mutex.initWithMutex(inner);
 
     // And test that our automatic unlocking wrapper works as expected.
     {
       SQLiteMutexAutoLock lockedScope(mutex);
 
       {