Bug 1311669 - use auto type specifier for variable declarations to improve code readability and maintainability. r=valentin
authorAndi-Bogdan Postelnicu <bpostelnicu@mozilla.com>
Tue, 01 Nov 2016 14:44:09 +0200
changeset 347188 9c3a2156b10a84d6621fd8c3ce1005e6c266beaa
parent 347187 81e30b16d0a13974856b573453fc67034d245738
child 347189 fa0e219113ac274e17a88b659e46d2f6e8af7166
push id10298
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:33:03 +0000
treeherdermozilla-aurora@7e29173b1641 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin
bugs1311669
milestone52.0a1
Bug 1311669 - use auto type specifier for variable declarations to improve code readability and maintainability. r=valentin MozReview-Commit-ID: F5YO9pVK5O8
netwerk/base/nsSocketTransportService2.cpp
netwerk/build/nsNetModule.cpp
netwerk/dns/DNS.cpp
netwerk/dns/nsDNSService2.cpp
netwerk/dns/nsHostResolver.cpp
netwerk/dns/nsIDNService.cpp
netwerk/protocol/http/AlternateServices.cpp
netwerk/protocol/http/nsHttpHandler.cpp
netwerk/sctp/datachannel/DataChannel.cpp
netwerk/streamconv/nsStreamConverterService.cpp
netwerk/test/TestProtocols.cpp
netwerk/wifi/osx_corewlan.mm
--- a/netwerk/base/nsSocketTransportService2.cpp
+++ b/netwerk/base/nsSocketTransportService2.cpp
@@ -174,17 +174,17 @@ nsSocketTransportService::NotifyWhenCanA
     SOCKET_LOG(("nsSocketTransportService::NotifyWhenCanAttachSocket\n"));
 
     NS_ASSERTION(PR_GetCurrentThread() == gSocketThread, "wrong thread");
 
     if (CanAttachSocket()) {
         return Dispatch(event, NS_DISPATCH_NORMAL);
     }
 
-    LinkedRunnableEvent *runnable = new LinkedRunnableEvent(event);
+    auto *runnable = new LinkedRunnableEvent(event);
     mPendingSocketQueue.insertBack(runnable);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSocketTransportService::AttachSocket(PRFileDesc *fd, nsASocketHandler *handler)
 {
     SOCKET_LOG(("nsSocketTransportService::AttachSocket [handler=%p]\n", handler));
--- a/netwerk/build/nsNetModule.cpp
+++ b/netwerk/build/nsNetModule.cpp
@@ -658,17 +658,17 @@ CreateNewBinaryDetectorFactory(nsISuppor
     return NS_ERROR_NULL_POINTER;
   }
   *aResult = nullptr;
 
   if (aOuter) {
     return NS_ERROR_NO_AGGREGATION;
   }
 
-  nsBinaryDetector* inst = new nsBinaryDetector();
+  auto* inst = new nsBinaryDetector();
   if (!inst) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
   NS_ADDREF(inst);
   rv = inst->QueryInterface(aIID, aResult);
   NS_RELEASE(inst);
 
   return rv;
--- a/netwerk/dns/DNS.cpp
+++ b/netwerk/dns/DNS.cpp
@@ -295,17 +295,17 @@ AddrInfo::AddrInfo(const char *host, con
   PRNetAddr tmpAddr;
   void *iter = nullptr;
   do {
     iter = PR_EnumerateAddrInfo(iter, prAddrInfo, 0, &tmpAddr);
     bool addIt = iter &&
         (!disableIPv4 || tmpAddr.raw.family != PR_AF_INET) &&
         (!filterNameCollision || tmpAddr.raw.family != PR_AF_INET || (tmpAddr.inet.ip != nameCollisionAddr));
     if (addIt) {
-        NetAddrElement *addrElement = new NetAddrElement(&tmpAddr);
+        auto *addrElement = new NetAddrElement(&tmpAddr);
         mAddresses.insertBack(addrElement);
     }
   } while (iter);
 }
 
 AddrInfo::AddrInfo(const char *host, const char *cname)
   : mHostName(nullptr)
   , mCanonicalName(nullptr)
--- a/netwerk/dns/nsDNSService2.cpp
+++ b/netwerk/dns/nsDNSService2.cpp
@@ -779,17 +779,17 @@ nsDNSService::AsyncResolveExtended(const
     }
 
     if (target) {
         listener = new DNSListenerProxy(listener, target);
     }
 
     uint16_t af = GetAFForLookup(hostname, flags);
 
-    nsDNSAsyncRequest *req =
+    auto *req =
         new nsDNSAsyncRequest(res, hostname, listener, flags, af,
                               aNetworkInterface);
     if (!req)
         return NS_ERROR_OUT_OF_MEMORY;
     NS_ADDREF(*result = req);
 
     // addref for resolver; will be released when OnLookupComplete is called.
     NS_ADDREF(req);
@@ -907,17 +907,17 @@ nsDNSService::Resolve(const nsACString &
         // wait for result
         while (!syncReq.mDone)
             PR_Wait(mon, PR_INTERVAL_NO_TIMEOUT);
 
         if (NS_FAILED(syncReq.mStatus))
             rv = syncReq.mStatus;
         else {
             NS_ASSERTION(syncReq.mHostRecord, "no host record");
-            nsDNSRecord *rec = new nsDNSRecord(syncReq.mHostRecord);
+            auto *rec = new nsDNSRecord(syncReq.mHostRecord);
             if (!rec)
                 rv = NS_ERROR_OUT_OF_MEMORY;
             else
                 NS_ADDREF(*result = rec);
         }
     }
 
     PR_ExitMonitor(mon);
--- a/netwerk/dns/nsHostResolver.cpp
+++ b/netwerk/dns/nsHostResolver.cpp
@@ -1514,17 +1514,17 @@ nsHostResolver::ThreadFunc(void *arg)
 }
 
 nsresult
 nsHostResolver::Create(uint32_t maxCacheEntries,
                        uint32_t defaultCacheEntryLifetime,
                        uint32_t defaultGracePeriod,
                        nsHostResolver **result)
 {
-    nsHostResolver *res = new nsHostResolver(maxCacheEntries, defaultCacheEntryLifetime,
+    auto *res = new nsHostResolver(maxCacheEntries, defaultCacheEntryLifetime,
                                              defaultGracePeriod);
     NS_ADDREF(res);
 
     nsresult rv = res->Init();
     if (NS_FAILED(rv))
         NS_RELEASE(res);
 
     *result = res;
--- a/netwerk/dns/nsIDNService.cpp
+++ b/netwerk/dns/nsIDNService.cpp
@@ -710,17 +710,17 @@ nsresult nsIDNService::decodeACE(const n
   nsAutoString utf16;
 #ifdef IDNA2008
   nsresult result = IDNA2008ToUnicode(in, utf16);
   NS_ENSURE_SUCCESS(result, result);
 #else
   // RFC 3490 - 4.2 ToUnicode
   // The ToUnicode output never contains more code points than its input.
   punycode_uint output_length = in.Length() - kACEPrefixLen + 1;
-  punycode_uint *output = new punycode_uint[output_length];
+  auto *output = new punycode_uint[output_length];
   NS_ENSURE_TRUE(output, NS_ERROR_OUT_OF_MEMORY);
 
   enum punycode_status status = punycode_decode(in.Length() - kACEPrefixLen,
                                                 PromiseFlatCString(in).get() + kACEPrefixLen,
                                                 &output_length,
                                                 output,
                                                 nullptr);
   if (status != punycode_success) {
--- a/netwerk/protocol/http/AlternateServices.cpp
+++ b/netwerk/protocol/http/AlternateServices.cpp
@@ -892,17 +892,17 @@ AltSvcCache::UpdateAltServiceMapping(Alt
       origin.AppendInt(map->OriginPort());
     }
 
     nsCOMPtr<nsIURI> wellKnown;
     nsAutoCString uri(origin);
     uri.Append(NS_LITERAL_CSTRING("/.well-known/http-opportunistic"));
     NS_NewURI(getter_AddRefs(wellKnown), uri);
 
-    WellKnownChecker *checker = new WellKnownChecker(wellKnown, origin, caps, ci, map);
+    auto *checker = new WellKnownChecker(wellKnown, origin, caps, ci, map);
     if (NS_FAILED(checker->Start())) {
       LOG(("AltSvcCache::UpdateAltServiceMapping %p .wk checker failed to start\n", this));
       map->SetExpired();
       delete checker;
       checker = nullptr;
     } else {
       // object deletes itself when done if started
       LOG(("AltSvcCache::UpdateAltServiceMapping %p .wk checker started %p\n", this, checker));
--- a/netwerk/protocol/http/nsHttpHandler.cpp
+++ b/netwerk/protocol/http/nsHttpHandler.cpp
@@ -2298,17 +2298,17 @@ nsHttpHandler::SpeculativeConnectInterna
 
     NeckoOriginAttributes neckoOriginAttributes;
     if (loadContext) {
       DocShellOriginAttributes docshellOriginAttributes;
       loadContext->GetOriginAttributes(docshellOriginAttributes);
       neckoOriginAttributes.InheritFromDocShellToNecko(docshellOriginAttributes);
     }
 
-    nsHttpConnectionInfo *ci =
+    auto *ci =
         new nsHttpConnectionInfo(host, port, EmptyCString(), username, nullptr,
                                  neckoOriginAttributes, usingSSL);
     ci->SetAnonymous(anonymous);
 
     return SpeculativeConnect(ci, aCallbacks);
 }
 
 NS_IMETHODIMP
--- a/netwerk/sctp/datachannel/DataChannel.cpp
+++ b/netwerk/sctp/datachannel/DataChannel.cpp
@@ -125,17 +125,17 @@ public:
 
 NS_IMPL_ISUPPORTS(DataChannelShutdown, nsIObserver);
 
 BufferedMsg::BufferedMsg(struct sctp_sendv_spa &spa, const char *data,
                          size_t length) : mLength(length)
 {
   mSpa = new sctp_sendv_spa;
   *mSpa = spa;
-  char *tmp = new char[length]; // infallible malloc!
+  auto *tmp = new char[length]; // infallible malloc!
   memcpy(tmp, data, length);
   mData = tmp;
 }
 
 BufferedMsg::~BufferedMsg()
 {
   delete mSpa;
   delete mData;
@@ -676,17 +676,17 @@ DataChannelConnection::SctpDtlsOutput(vo
   // We're async proxying even if on the STSThread because this is called
   // with internal SCTP locks held in some cases (such as in usrsctp_connect()).
   // SCTP has an option for Apple, on IP connections only, to release at least
   // one of the locks before calling a packet output routine; with changes to
   // the underlying SCTP stack this might remove the need to use an async proxy.
   if ((0 /*peer->IsSTSThread()*/)) {
     res = peer->SendPacket(static_cast<unsigned char *>(buffer), length, false);
   } else {
-    unsigned char *data = new unsigned char[length];
+    auto *data = new unsigned char[length];
     memcpy(data, buffer, length);
     // Commented out since we have to Dispatch SendPacket to avoid deadlock"
     // res = -1;
 
     // XXX It might be worthwhile to add an assertion against the thread
     // somehow getting into the DataChannel/SCTP code again, as
     // DISPATCH_SYNC is not fully blocking.  This may be tricky, as it
     // needs to be a per-thread check, not a global.
@@ -2225,17 +2225,17 @@ DataChannelConnection::SendMsgInternal(D
     // Fake EAGAIN if we're already buffering data
     result = -1;
     errno = EAGAIN;
   }
   if (result < 0) {
     if (errno == EAGAIN || errno == EWOULDBLOCK) {
 
       // queue data for resend!  And queue any further data for the stream until it is...
-      BufferedMsg *buffered = new BufferedMsg(spa, data, length); // infallible malloc
+      auto *buffered = new BufferedMsg(spa, data, length); // infallible malloc
       channel->mBufferedData.AppendElement(buffered); // owned by mBufferedData array
       channel->mFlags |= DATA_CHANNEL_FLAGS_SEND_DATA;
       LOG(("Queued %u buffers (len=%u)", channel->mBufferedData.Length(), length));
       return 0;
     }
     LOG(("error %d sending string", errno));
   }
   return result;
--- a/netwerk/streamconv/nsStreamConverterService.cpp
+++ b/netwerk/streamconv/nsStreamConverterService.cpp
@@ -234,17 +234,17 @@ nsStreamConverterService::FindConverter(
 
     BFSTableData *data = lBFSTable.Get(fromC);
     if (!data) {
         return NS_ERROR_FAILURE;
     }
 
     data->color = gray;
     data->distance = 0;
-    CStreamConvDeallocator *dtorFunc = new CStreamConvDeallocator();
+    auto *dtorFunc = new CStreamConvDeallocator();
 
     nsDeque grayQ(dtorFunc);
 
     // Now generate the shortest path tree.
     grayQ.Push(new nsCString(fromC));
     while (0 < grayQ.GetSize()) {
         nsCString *currentHead = (nsCString*)grayQ.PeekFront();
         nsCOMArray<nsIAtom> *data2 = mAdjacencyList.Get(*currentHead);
@@ -254,17 +254,17 @@ nsStreamConverterService::FindConverter(
         // reachable vertex in the loop.
         BFSTableData *headVertexState = lBFSTable.Get(*currentHead);
         if (!headVertexState) return NS_ERROR_FAILURE;
 
         int32_t edgeCount = data2->Count();
 
         for (int32_t i = 0; i < edgeCount; i++) {
             nsIAtom* curVertexAtom = data2->ObjectAt(i);
-            nsCString *curVertex = new nsCString();
+            auto *curVertex = new nsCString();
             curVertexAtom->ToUTF8String(*curVertex);
 
             BFSTableData *curVertexState = lBFSTable.Get(*curVertex);
             if (!curVertexState) {
                 delete curVertex;
                 return NS_ERROR_FAILURE;
             }
 
@@ -290,17 +290,17 @@ nsStreamConverterService::FindConverter(
     // first parse out the FROM and TO MIME-types being registered.
 
     nsAutoCString fromStr, toMIMEType;
     rv = ParseFromTo(aContractID, fromStr, toMIMEType);
     if (NS_FAILED(rv)) return rv;
 
     // get the root CONTRACTID
     nsAutoCString ContractIDPrefix(NS_ISTREAMCONVERTER_KEY);
-    nsTArray<nsCString> *shortestPath = new nsTArray<nsCString>();
+    auto *shortestPath = new nsTArray<nsCString>();
 
     data = lBFSTable.Get(toMIMEType);
     if (!data) {
         // If this vertex isn't in the BFSTable, then no-one has registered for it,
         // therefore we can't do the conversion.
         delete shortestPath;
         return NS_ERROR_FAILURE;
     }
--- a/netwerk/test/TestProtocols.cpp
+++ b/netwerk/test/TestProtocols.cpp
@@ -441,17 +441,17 @@ InputTestConsumer::OnStartRequest(nsIReq
       uint32_t majorVer, minorVer;
       nsresult rv = httpChannelInt->GetResponseVersion(&majorVer, &minorVer);
       if (NS_SUCCEEDED(rv)) {
           LOG(("HTTP Response version: %u.%u\n", majorVer, minorVer));
       }
   }
   nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(request));
   if (httpChannel) {
-    HeaderVisitor *visitor = new HeaderVisitor();
+    auto *visitor = new HeaderVisitor();
     if (!visitor)
       return NS_ERROR_OUT_OF_MEMORY;
     NS_ADDREF(visitor);
 
     LOG(("HTTP request headers:\n"));
     httpChannel->VisitRequestHeaders(visitor);
 
     LOG(("HTTP response headers:\n"));
@@ -619,17 +619,17 @@ nsresult StartLoadingURL(const char* aUr
 
         rv = pService->NewURI(nsDependentCString(aUrlString), nullptr, nullptr, getter_AddRefs(pURL));
         if (NS_FAILED(rv)) {
             LOG(("ERROR: NewURI failed for %s [rv=%x]\n", aUrlString));
             return rv;
         }
         nsCOMPtr<nsIChannel> pChannel;
 
-        NotificationCallbacks* callbacks = new NotificationCallbacks();
+        auto* callbacks = new NotificationCallbacks();
         if (!callbacks) {
             LOG(("Failed to create a new consumer!"));
             return NS_ERROR_OUT_OF_MEMORY;;
         }
         NS_ADDREF(callbacks);
 
         nsCOMPtr<nsIScriptSecurityManager> secman =
           do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
@@ -677,23 +677,23 @@ nsresult StartLoadingURL(const char* aUr
 
         if (pHTTPCon) {
             // Setting a sample header.
             rv = pHTTPCon->SetRequestHeader(NS_LITERAL_CSTRING("sample-header"),
                                             NS_LITERAL_CSTRING("Sample-Value"),
                                             false);
             if (NS_FAILED(rv)) return rv;
         }            
-        URLLoadInfo* info = new URLLoadInfo(aUrlString);
+        auto* info = new URLLoadInfo(aUrlString);
         if (!info) {
             NS_ERROR("Failed to create a load info!");
             return NS_ERROR_OUT_OF_MEMORY;
         }
 
-        InputTestConsumer* listener = new InputTestConsumer(info);
+        auto* listener = new InputTestConsumer(info);
         NS_IF_ADDREF(listener);
         if (!listener) {
             NS_ERROR("Failed to create a new stream listener!");
             return NS_ERROR_OUT_OF_MEMORY;;
         }
 
 
         if (gResume) {
--- a/netwerk/wifi/osx_corewlan.mm
+++ b/netwerk/wifi/osx_corewlan.mm
@@ -44,17 +44,17 @@ GetAccessPointsFromWLAN(nsCOMArray<nsWif
       [pool release];
       return NS_ERROR_NOT_AVAILABLE;
     }
 
     NSArray* scan = [NSMutableArray arrayWithArray:scanResult];
     NSEnumerator *enumerator = [scan objectEnumerator];
 
     while (id anObject = [enumerator nextObject]) {
-      nsWifiAccessPoint* ap = new nsWifiAccessPoint();
+      auto* ap = new nsWifiAccessPoint();
       if (!ap) {
         [pool release];
         return NS_ERROR_OUT_OF_MEMORY;
       }
 
       // [CWInterface bssidData] is deprecated on OS X 10.7 and up.  Which is
       // is a pain, so we'll use it for as long as it's available.
       unsigned char macData[6] = {0};