Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2739)

Unified Diff: Source/wtf/ArrayBufferContents.cpp

Issue 22038002: Get rid of the tryFast*alloc API. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Review item. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/wtf/ArrayBufferContents.h ('k') | Source/wtf/FastAllocBase.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/wtf/ArrayBufferContents.cpp
diff --git a/Source/wtf/ArrayBufferContents.cpp b/Source/wtf/ArrayBufferContents.cpp
index f62734bf8d5613b43965da9569c91c2f088f751c..03702d82ee5f7ed8d54d85311357e4d464f60d82 100644
--- a/Source/wtf/ArrayBufferContents.cpp
+++ b/Source/wtf/ArrayBufferContents.cpp
@@ -28,6 +28,7 @@
#include "wtf/ArrayBufferContents.h"
#include "wtf/ArrayBufferDeallocationObserver.h"
+#include "wtf/Assertions.h"
#include <string.h>
namespace WTF {
@@ -43,9 +44,6 @@ ArrayBufferContents::ArrayBufferContents(unsigned numElements, unsigned elementB
, m_deallocationObserver(0)
{
// Do not allow 32-bit overflow of the total size.
- // FIXME: Why not? The tryFastCalloc function already checks its arguments,
- // and will fail if there is any overflow, so why should we include a
- // redudant unnecessarily restrictive check here?
if (numElements) {
unsigned totalSize = numElements * elementByteSize;
if (totalSize / numElements != elementByteSize) {
@@ -53,11 +51,8 @@ ArrayBufferContents::ArrayBufferContents(unsigned numElements, unsigned elementB
return;
}
}
- if (allocateMemory(numElements * elementByteSize, policy, m_data)) {
- m_sizeInBytes = numElements * elementByteSize;
- return;
- }
- m_data = 0;
+ allocateMemory(numElements * elementByteSize, policy, m_data);
+ m_sizeInBytes = numElements * elementByteSize;
}
ArrayBufferContents::ArrayBufferContents(void* data, unsigned sizeInBytes)
@@ -70,8 +65,7 @@ ArrayBufferContents::ArrayBufferContents(void* data, unsigned sizeInBytes)
m_sizeInBytes = 0;
// Allow null data if size is 0 bytes, make sure m_data is valid pointer.
// (fastMalloc guarantees valid pointer for size 0)
- if (!allocateMemory(0, ZeroInitialize, m_data))
- ASSERT_NOT_REACHED();
+ allocateMemory(0, ZeroInitialize, m_data);
}
}
@@ -109,13 +103,11 @@ void ArrayBufferContents::copyTo(ArrayBufferContents& other)
other.m_sizeInBytes = m_sizeInBytes;
}
-bool ArrayBufferContents::allocateMemory(size_t size, InitializationPolicy policy, void*& data)
+void ArrayBufferContents::allocateMemory(size_t size, InitializationPolicy policy, void*& data)
{
- if (policy == ZeroInitialize) {
- return WTF::tryFastCalloc(size, 1).getValue(data);
- }
- ASSERT(policy == DontInitialize);
- return WTF::tryFastMalloc(size).getValue(data);
+ data = WTF::fastMalloc(size);
+ if (policy == ZeroInitialize)
+ memset(data, '\0', size);
}
void ArrayBufferContents::freeMemory(void * data)
« no previous file with comments | « Source/wtf/ArrayBufferContents.h ('k') | Source/wtf/FastAllocBase.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698