Bug 1485142: Make url-classifier 'PartialHashHex()' API return a nsAutoCString instead of nsCString, to address build warning & reduce copying. r=gcp
authorDaniel Holbert <dholbert@cs.stanford.edu>
Wed, 22 Aug 2018 16:51:56 +0000
changeset 487970 73e2097aa0c3347c3fe743d125a10bb565b0e099
parent 487969 4dbf6f8f9990cc2e834cc0f2b09707e16d373500
child 487971 ab8b409edb0eb65164855cc3d237cf767fb382a5
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgcp
bugs1485142
milestone63.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 1485142: Make url-classifier 'PartialHashHex()' API return a nsAutoCString instead of nsCString, to address build warning & reduce copying. r=gcp Before this patch -- with the nsCString return type -- we have to do heap allocation and copying to produce the return value. But the callers don't actually care about having a nsCString -- they just call .get() to access the character buffer, and log it, and then they're done. They can do this just as easily with the stack-allocated nsAutoCString that PartialHashHex() works with locally, so let's change the return type so that Return Value Optimization can give them that variable directly and avoid needless copying/allocation. This patch addresses the following clang 8.0 build warning: LookupCache.h:63:12 [-Wreturn-std-move] local variable 'hex' will be copied despite being returned by name Differential Revision: https://phabricator.services.mozilla.com/D3920
toolkit/components/url-classifier/LookupCache.h
--- a/toolkit/components/url-classifier/LookupCache.h
+++ b/toolkit/components/url-classifier/LookupCache.h
@@ -50,17 +50,17 @@ public:
       return nsCString(reinterpret_cast<const char*>(hash.fixedLengthPrefix.buf),
                        PREFIX_SIZE);
     } else {
       return nsCString(reinterpret_cast<const char*>(hash.complete.buf),
                        mPartialHashLength);
     }
   }
 
-  nsCString PartialHashHex() const {
+  nsAutoCString PartialHashHex() const {
     nsAutoCString hex;
     for (size_t i = 0; i < mPartialHashLength; i++) {
       hex.AppendPrintf("%.2X", hash.complete.buf[i]);
     }
     return hex;
   }
 
   bool Confirmed() const { return mConfirmed || mProtocolConfirmed; }