Bug 1067018 - Make sure calloc/malloc/free usages match in Tools.h. r=jwatt, a=sledru
authorJim Chen <nchen@mozilla.com>
Thu, 25 Sep 2014 13:08:23 -0400
changeset 216856 cf8866bd741f
parent 216855 badc5be25cc1
child 216857 b57f0af03f78
push id3942
push userryanvm@gmail.com
push date2014-09-26 13:41 +0000
treeherdermozilla-beta@2b061899d368 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwatt, sledru
bugs1067018
milestone33.0
Bug 1067018 - Make sure calloc/malloc/free usages match in Tools.h. r=jwatt, a=sledru
gfx/2d/Tools.h
--- a/gfx/2d/Tools.h
+++ b/gfx/2d/Tools.h
@@ -128,38 +128,40 @@ struct AlignedArray
       // Since we used the placement |operator new| function to construct the
       // elements of this array we need to invoke their destructors manually.
       // For types where the destructor does nothing the compiler's dead code
       // elimination step should optimize this loop away.
       mPtr[i].~T();
     }
 #endif
 
-    delete [] mStorage;
+    moz_free(mStorage);
     mStorage = nullptr;
     mPtr = nullptr;
   }
 
   MOZ_ALWAYS_INLINE void Realloc(size_t aCount, bool aZero = false)
   {
-    delete [] mStorage;
+    moz_free(mStorage);
     CheckedInt32 storageByteCount =
       CheckedInt32(sizeof(T)) * aCount + (alignment - 1);
     if (!storageByteCount.isValid()) {
       mStorage = nullptr;
       mPtr = nullptr;
       mCount = 0;
       return;
     }
     // We don't create an array of T here, since we don't want ctors to be
     // invoked at the wrong places if we realign below.
     if (aZero) {
-      mStorage = static_cast<uint8_t *>(calloc(1, storageByteCount.value()));
+      // calloc can be more efficient than new[] for large chunks,
+      // so we use calloc/malloc/free for everything.
+      mStorage = static_cast<uint8_t *>(moz_calloc(1, storageByteCount.value()));
     } else {
-      mStorage = new (std::nothrow) uint8_t[storageByteCount.value()];
+      mStorage = static_cast<uint8_t *>(moz_malloc(storageByteCount.value()));
     }
     if (!mStorage) {
       mStorage = nullptr;
       mPtr = nullptr;
       mCount = 0;
       return;
     }
     if (uintptr_t(mStorage) % alignment) {