Bug 1344830: Convert to range-based 'for' loops in U2F.cpp. r=jcj
authorDaniel Holbert <dholbert@cs.stanford.edu>
Mon, 06 Mar 2017 11:16:54 -0800
changeset 346121 072038384d3e3d527b58d8558d7ebe720fa60ef0
parent 346120 828486abb626e719d99ecca788ed426e72cf1748
child 346122 7a576717126b2a992937d4714733ad7e43f29474
push id31459
push usercbook@mozilla.com
push dateTue, 07 Mar 2017 14:05:14 +0000
treeherdermozilla-central@1fb56ba248d5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjcj
bugs1344830
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1344830: Convert to range-based 'for' loops in U2F.cpp. r=jcj MozReview-Commit-ID: 2PRQw4Pxquq
dom/u2f/U2F.cpp
--- a/dom/u2f/U2F.cpp
+++ b/dom/u2f/U2F.cpp
@@ -530,19 +530,17 @@ U2FRegisterRunnable::U2FRegisterRunnable
   // U2FRegisterCallback does not support threadsafe refcounting, and must be
   // used and destroyed on main.
   , mCallback(new nsMainThreadPtrHolder<U2FRegisterCallback>(aCallback))
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   // The WebIDL dictionary types RegisterRequest and RegisteredKey cannot
   // be copied to this thread, so store them serialized.
-  for (size_t i = 0; i < aRegisterRequests.Length(); ++i) {
-    RegisterRequest req(aRegisterRequests[i]);
-
+  for (const RegisterRequest& req : aRegisterRequests) {
     // Check for required attributes
     if (!req.mChallenge.WasPassed() || !req.mVersion.WasPassed()) {
       continue;
     }
 
     LocalRegisterRequest localReq;
     localReq.mVersion = req.mVersion.Value();
     localReq.mChallenge = req.mChallenge.Value();
@@ -551,19 +549,17 @@ U2FRegisterRunnable::U2FRegisterRunnable
                                      localReq.mChallenge, localReq.mClientData);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       continue;
     }
 
     mRegisterRequests.AppendElement(localReq);
   }
 
-  for (size_t i = 0; i < aRegisteredKeys.Length(); ++i) {
-    RegisteredKey key(aRegisteredKeys[i]);
-
+  for (const RegisteredKey& key : aRegisteredKeys) {
     // Check for required attributes
     if (!key.mVersion.WasPassed() || !key.mKeyHandle.WasPassed()) {
       continue;
     }
 
     LocalRegisteredKey localKey;
     localKey.mVersion = key.mVersion.Value();
     localKey.mKeyHandle = key.mKeyHandle.Value();
@@ -619,20 +615,19 @@ U2FRegisterRunnable::Run()
   // Evaluate the AppID
   ErrorCode appIdResult = EvaluateAppID();
   if (appIdResult != ErrorCode::OK) {
     status->Stop(appIdResult);
   }
 
   // First, we must determine if any of the RegisteredKeys are already
   // registered, e.g., in the whitelist.
-  for (LocalRegisteredKey key: mRegisteredKeys) {
+  for (LocalRegisteredKey key : mRegisteredKeys) {
     nsTArray<RefPtr<U2FPrepPromise>> prepPromiseList;
-    for (size_t a = 0; a < mAuthenticators.Length(); ++a) {
-      Authenticator token(mAuthenticators[a]);
+    for (const Authenticator& token : mAuthenticators) {
       RefPtr<U2FIsRegisteredTask> compTask =
         new U2FIsRegisteredTask(token, key, mAbstractMainThread);
       prepPromiseList.AppendElement(compTask->Execute());
     }
 
     // Treat each call to Promise::All as a work unit, as it completes together
     status->WaitGroupAdd();
 
@@ -699,18 +694,17 @@ U2FRegisterRunnable::Run()
     }
 
     srv = PK11_HashBuf(SEC_OID_SHA256, challengeParam.Elements(),
                        req.mClientData.Elements(), req.mClientData.Length());
     if (srv != SECSuccess) {
       continue;
     }
 
-    for (size_t a = 0; a < mAuthenticators.Length(); ++a) {
-      Authenticator token(mAuthenticators[a]);
+    for (const Authenticator& token : mAuthenticators) {
       RefPtr<U2FRegisterTask> registerTask = new U2FRegisterTask(mOrigin, mAppId,
                                                                  token, appParam,
                                                                  challengeParam,
                                                                  req,
                                                                  mAbstractMainThread);
       status->WaitGroupAdd();
 
       registerTask->Execute()->Then(mAbstractMainThread, __func__,
@@ -769,19 +763,17 @@ U2FSignRunnable::U2FSignRunnable(const n
   , mAuthenticators(aAuthenticators)
   // U2FSignCallback does not support threadsafe refcounting, and must be used
   // and destroyed on main.
   , mCallback(new nsMainThreadPtrHolder<U2FSignCallback>(aCallback))
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   // Convert WebIDL objects to generic structs to pass between threads
-  for (size_t i = 0; i < aRegisteredKeys.Length(); ++i) {
-    RegisteredKey key(aRegisteredKeys[i]);
-
+  for (const RegisteredKey& key : aRegisteredKeys) {
     // Check for required attributes
     if (!key.mVersion.WasPassed() || !key.mKeyHandle.WasPassed()) {
       continue;
     }
 
     LocalRegisteredKey localKey;
     localKey.mVersion = key.mVersion.Value();
     localKey.mKeyHandle = key.mKeyHandle.Value();
@@ -884,19 +876,17 @@ U2FSignRunnable::Run()
     nsresult rv = keyHandle.FromJwkBase64(key.mKeyHandle);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       continue;
     }
 
     // We ignore mTransports, as it is intended to be used for sorting the
     // available devices by preference, but is not an exclusion factor.
 
-    for (size_t a = 0; a < mAuthenticators.Length() ; ++a) {
-      Authenticator token(mAuthenticators[a]);
-
+    for (const Authenticator& token : mAuthenticators) {
       RefPtr<U2FSignTask> signTask = new U2FSignTask(mOrigin, mAppId,
                                                      key.mVersion, token,
                                                      appParam, challengeParam,
                                                      mClientData, keyHandle,
                                                      mAbstractMainThread);
       status->WaitGroupAdd();
 
       signTask->Execute()->Then(mAbstractMainThread, __func__,