Bug 1249389 - part 5 - use UniquePtr instead of nsAutoArrayPtr in mozilla::scache::CacheEntry; r=erahm
authorNathan Froyd <froydnj@mozilla.com>
Thu, 18 Feb 2016 14:14:28 -0500
changeset 323690 bcfb36dfee0fea8de1555b658b6b04d30ccad263
parent 323689 50332bf18a2fd8f6be9b69fb0e2482da8d528987
child 323691 2a3bc10a643708d268364d928c2342bb5930f8d7
push id1128
push userjlund@mozilla.com
push dateWed, 01 Jun 2016 01:31:59 +0000
treeherdermozilla-release@fe0d30de989d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerserahm
bugs1249389
milestone47.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 1249389 - part 5 - use UniquePtr instead of nsAutoArrayPtr in mozilla::scache::CacheEntry; r=erahm
startupcache/StartupCache.cpp
startupcache/StartupCache.h
--- a/startupcache/StartupCache.cpp
+++ b/startupcache/StartupCache.cpp
@@ -311,17 +311,17 @@ StartupCache::GetBuffer(const char* id, 
 
   WaitOnWriteThread();
   if (!mStartupWriteInitiated) {
     CacheEntry* entry; 
     nsDependentCString idStr(id);
     mTable.Get(idStr, &entry);
     if (entry) {
       *outbuf = MakeUnique<char[]>(entry->size);
-      memcpy(outbuf->get(), entry->data, entry->size);
+      memcpy(outbuf->get(), entry->data.get(), entry->size);
       *length = entry->size;
       return NS_OK;
     }
   }
 
   nsresult rv = GetBufferFromZipArchive(mArchive, true, id, outbuf, length);
   if (NS_SUCCEEDED(rv))
     return rv;
@@ -342,18 +342,18 @@ nsresult
 StartupCache::PutBuffer(const char* id, const char* inbuf, uint32_t len) 
 {
   NS_ASSERTION(NS_IsMainThread(), "Startup cache only available on main thread");
   WaitOnWriteThread();
   if (StartupCache::gShutdownInitiated) {
     return NS_ERROR_NOT_AVAILABLE;
   }
 
-  nsAutoArrayPtr<char> data(new char[len]);
-  memcpy(data, inbuf, len);
+  auto data = MakeUnique<char[]>(len);
+  memcpy(data.get(), inbuf, len);
 
   nsCString idStr(id);
   // Cache it for now, we'll write all together later.
   CacheEntry* entry; 
   
   if (mTable.Get(idStr)) {
     NS_ASSERTION(false, "Existing entry in StartupCache.");
     // Double-caching is undesirable but not an error.
@@ -362,17 +362,17 @@ StartupCache::PutBuffer(const char* id, 
 
 #ifdef DEBUG
   if (mArchive) {
     nsZipItem* zipItem = mArchive->GetItem(id);
     NS_ASSERTION(zipItem == nullptr, "Existing entry in disk StartupCache.");
   }
 #endif
 
-  entry = new CacheEntry(data.forget(), len);
+  entry = new CacheEntry(Move(data), len);
   mTable.Put(idStr, entry);
   mPendingWrites.AppendElement(idStr);
   return ResetStartupWriteTimer();
 }
 
 size_t
 StartupCache::SizeOfMapping()
 {
@@ -409,17 +409,17 @@ CacheCloseHelper(const nsACString& key, 
                  const CacheWriteHolder* holder)
 {
   MOZ_ASSERT(data); // assert key was found in mTable.
 
   nsresult rv;
   nsIStringInputStream* stream = holder->stream;
   nsIZipWriter* writer = holder->writer;
 
-  stream->ShareData(data->data, data->size);
+  stream->ShareData(data->data.get(), data->size);
 
 #ifdef DEBUG
   bool hasEntry;
   rv = writer->HasEntry(key, &hasEntry);
   NS_ASSERTION(NS_SUCCEEDED(rv) && hasEntry == false, 
                "Existing entry in disk StartupCache.");
 #endif
   rv = writer->AddEntryStream(key, holder->time, true, stream, false);
--- a/startupcache/StartupCache.h
+++ b/startupcache/StartupCache.h
@@ -69,30 +69,30 @@
  */
 
 namespace mozilla {
 
 namespace scache {
 
 struct CacheEntry
 {
-  nsAutoArrayPtr<char> data;
+  UniquePtr<char[]> data;
   uint32_t size;
 
-  CacheEntry() : data(nullptr), size(0) { }
+  CacheEntry() : size(0) { }
 
   // Takes possession of buf
-  CacheEntry(char* buf, uint32_t len) : data(buf), size(len) { }
+  CacheEntry(UniquePtr<char[]> buf, uint32_t len) : data(Move(buf)), size(len) { }
 
   ~CacheEntry()
   {
   }
 
   size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) {
-    return mallocSizeOf(this) + mallocSizeOf(data);
+    return mallocSizeOf(this) + mallocSizeOf(data.get());
   }
 };
 
 // We don't want to refcount StartupCache, and ObserverService wants to
 // refcount its listeners, so we'll let it refcount this instead.
 class StartupCacheListener final : public nsIObserver
 {
   ~StartupCacheListener() {}