Bug 1317430 - Avoid a unnecessary copy by passing a const & in netwerk/ draft
authorSylvestre Ledru <sledru@mozilla.com>
Mon, 14 Nov 2016 23:16:40 +0100
changeset 438676 d30bb3453a595a05662f7eb6293985a229377a1e
parent 438675 3948f7b394c541e6d46c870f32309bdb8cb2be80
child 438677 df37d2c3a3c709142096b2da4dd405ec2b7def6d
push id35794
push usersledru@mozilla.com
push dateMon, 14 Nov 2016 22:18:09 +0000
bugs1317430
milestone52.0a1
Bug 1317430 - Avoid a unnecessary copy by passing a const & in netwerk/ MozReview-Commit-ID: LKgXjObeXOZ
netwerk/base/Dashboard.h
netwerk/cookie/nsCookieService.cpp
netwerk/cookie/nsCookieService.h
netwerk/protocol/http/ASpdySession.cpp
netwerk/protocol/http/AlternateServices.cpp
netwerk/protocol/http/AlternateServices.h
netwerk/protocol/http/PSpdyPush.h
netwerk/sctp/datachannel/DataChannel.h
--- a/netwerk/base/Dashboard.h
+++ b/netwerk/base/Dashboard.h
@@ -64,17 +64,17 @@ private:
         }
     };
 
     struct WebSocketData
     {
         WebSocketData():lock("Dashboard.webSocketData")
         {
         }
-        uint32_t IndexOf(nsCString hostname, uint32_t mSerial)
+        uint32_t IndexOf(const nsCString& hostname, uint32_t mSerial)
         {
             LogData temp(hostname, mSerial, false);
             return data.IndexOf(temp);
         }
         nsTArray<LogData> data;
         mozilla::Mutex lock;
     };
 
--- a/netwerk/cookie/nsCookieService.cpp
+++ b/netwerk/cookie/nsCookieService.cpp
@@ -3111,17 +3111,17 @@ PathMatches(nsCookie* aCookie, const nsA
   // the given path.
   return true;
 }
 
 void
 nsCookieService::GetCookieStringInternal(nsIURI *aHostURI,
                                          bool aIsForeign,
                                          bool aHttpBound,
-                                         const NeckoOriginAttributes aOriginAttrs,
+                                         const NeckoOriginAttributes& aOriginAttrs,
                                          bool aIsPrivate,
                                          nsCString &aCookieString)
 {
   NS_ASSERTION(aHostURI, "null host!");
 
   if (!mDBState) {
     NS_WARNING("No DBState! Profile already closed?");
     return;
--- a/netwerk/cookie/nsCookieService.h
+++ b/netwerk/cookie/nsCookieService.h
@@ -288,17 +288,17 @@ class nsCookieService final : public nsI
     void                          AsyncReadComplete();
     void                          CancelAsyncRead(bool aPurgeReadSet);
     void                          EnsureReadDomain(const nsCookieKey &aKey);
     void                          EnsureReadComplete();
     nsresult                      NormalizeHost(nsCString &aHost);
     nsresult                      GetBaseDomain(nsIURI *aHostURI, nsCString &aBaseDomain, bool &aRequireHostMatch);
     nsresult                      GetBaseDomainFromHost(const nsACString &aHost, nsCString &aBaseDomain);
     nsresult                      GetCookieStringCommon(nsIURI *aHostURI, nsIChannel *aChannel, bool aHttpBound, char** aCookie);
-    void                          GetCookieStringInternal(nsIURI *aHostURI, bool aIsForeign, bool aHttpBound, const NeckoOriginAttributes aOriginAttrs, bool aIsPrivate, nsCString &aCookie);
+    void                          GetCookieStringInternal(nsIURI *aHostURI, bool aIsForeign, bool aHttpBound, const NeckoOriginAttributes& aOriginAttrs, bool aIsPrivate, nsCString &aCookie);
     nsresult                      SetCookieStringCommon(nsIURI *aHostURI, const char *aCookieHeader, const char *aServerTime, nsIChannel *aChannel, bool aFromHttp);
     void                          SetCookieStringInternal(nsIURI *aHostURI, bool aIsForeign, nsDependentCString &aCookieHeader, const nsCString &aServerTime, bool aFromHttp, const NeckoOriginAttributes &aOriginAttrs, bool aIsPrivate, nsIChannel* aChannel);
     bool                          SetCookieInternal(nsIURI *aHostURI, const nsCookieKey& aKey, bool aRequireHostMatch, CookieStatus aStatus, nsDependentCString &aCookieHeader, int64_t aServerTime, bool aFromHttp, nsIChannel* aChannel);
     void                          AddInternal(const nsCookieKey& aKey, nsCookie *aCookie, int64_t aCurrentTimeInUsec, nsIURI *aHostURI, const char *aCookieHeader, bool aFromHttp);
     void                          RemoveCookieFromList(const nsListIter &aIter, mozIStorageBindingParamsArray *aParamsArray = nullptr);
     void                          AddCookieToList(const nsCookieKey& aKey, nsCookie *aCookie, DBState *aDBState, mozIStorageBindingParamsArray *aParamsArray, bool aWriteToDB = true);
     void                          UpdateCookieInList(nsCookie *aCookie, int64_t aLastAccessed, mozIStorageBindingParamsArray *aParamsArray);
     static bool                   GetTokenValue(nsASingleFragmentCString::const_char_iterator &aIter, nsASingleFragmentCString::const_char_iterator &aEndIter, nsDependentCSubstring &aTokenString, nsDependentCSubstring &aTokenValue, bool &aEqualsFound);
--- a/netwerk/protocol/http/ASpdySession.cpp
+++ b/netwerk/protocol/http/ASpdySession.cpp
@@ -92,32 +92,32 @@ SpdyPushCache::SpdyPushCache()
 }
 
 SpdyPushCache::~SpdyPushCache()
 {
   mHashHttp2.Clear();
 }
 
 bool
-SpdyPushCache::RegisterPushedStreamHttp2(nsCString key,
+SpdyPushCache::RegisterPushedStreamHttp2(const nsCString& key,
                                          Http2PushedStream *stream)
 {
   LOG3(("SpdyPushCache::RegisterPushedStreamHttp2 %s 0x%X\n",
         key.get(), stream->StreamID()));
   if(mHashHttp2.Get(key)) {
     LOG3(("SpdyPushCache::RegisterPushedStreamHttp2 %s 0x%X duplicate key\n",
           key.get(), stream->StreamID()));
     return false;
   }
   mHashHttp2.Put(key, stream);
   return true;
 }
 
 Http2PushedStream *
-SpdyPushCache::RemovePushedStreamHttp2(nsCString key)
+SpdyPushCache::RemovePushedStreamHttp2(const nsCString& key)
 {
   Http2PushedStream *rv = mHashHttp2.Get(key);
   LOG3(("SpdyPushCache::RemovePushedStreamHttp2 %s 0x%X\n",
         key.get(), rv ? rv->StreamID() : 0));
   if (rv)
     mHashHttp2.Remove(key);
   return rv;
 }
--- a/netwerk/protocol/http/AlternateServices.cpp
+++ b/netwerk/protocol/http/AlternateServices.cpp
@@ -235,17 +235,17 @@ AltSvcMapping::MakeHashKey(nsCString &ou
 
 int32_t
 AltSvcMapping::TTL()
 {
   return mExpiresAt - NowInSeconds();
 }
 
 void
-AltSvcMapping::SyncString(nsCString str)
+AltSvcMapping::SyncString(const nsCString& str)
 {
   MOZ_ASSERT(NS_IsMainThread());
   mStorage->Put(HashKey(), str,
                 mPrivate ? DataStorage_Private : DataStorage_Persistent);
 }
 
 void
 AltSvcMapping::Sync()
--- a/netwerk/protocol/http/AlternateServices.h
+++ b/netwerk/protocol/http/AlternateServices.h
@@ -91,17 +91,17 @@ public:
   static void MakeHashKey(nsCString &outKey,
                           const nsACString &originScheme,
                           const nsACString &originHost,
                           int32_t originPort,
                           bool privateBrowsing);
 
 private:
   virtual ~AltSvcMapping() {};
-  void     SyncString(nsCString val);
+  void     SyncString(const nsCString& val);
   RefPtr<DataStorage> mStorage;
   int32_t             mStorageEpoch;
   void Serialize (nsCString &out);
 
   nsCString mHashKey;
 
   // If you change any of these members, update Serialize()
   nsCString mAlternateHost;
--- a/netwerk/protocol/http/PSpdyPush.h
+++ b/netwerk/protocol/http/PSpdyPush.h
@@ -38,19 +38,19 @@ class Http2PushedStream;
 
 // One cache per load group
 class SpdyPushCache
 {
 public:
   // The cache holds only weak pointers - no references
   SpdyPushCache();
   virtual ~SpdyPushCache();
-  bool               RegisterPushedStreamHttp2(nsCString key,
+  bool               RegisterPushedStreamHttp2(const nsCString& key,
                                                Http2PushedStream *stream);
-  Http2PushedStream *RemovePushedStreamHttp2(nsCString key);
+  Http2PushedStream *RemovePushedStreamHttp2(const nsCString& key);
 private:
   nsDataHashtable<nsCStringHashKey, Http2PushedStream *> mHashHttp2;
 };
 
 } // namespace net
 } // namespace mozilla
 
 #endif // mozilla_net_SpdyPush_Public_h
--- a/netwerk/sctp/datachannel/DataChannel.h
+++ b/netwerk/sctp/datachannel/DataChannel.h
@@ -250,17 +250,17 @@ private:
     if (mSTS) {
       mSTS->IsOnCurrentThread(&on);
     }
     return on;
   }
 #endif
 
   // Exists solely for proxying release of the TransportFlow to the STS thread
-  static void ReleaseTransportFlow(RefPtr<TransportFlow> aFlow) {}
+  static void ReleaseTransportFlow(const RefPtr<TransportFlow>& aFlow) {}
 
   // Data:
   // NOTE: while this array will auto-expand, increases in the number of
   // channels available from the stack must be negotiated!
   bool mAllocateEven;
   AutoTArray<RefPtr<DataChannel>,16> mStreams;
   nsDeque mPending; // Holds addref'ed DataChannel's -- careful!
   // holds data that's come in before a channel is open