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

Unified Diff: Source/wtf/ArrayBuffer.h

Issue 1186863005: Add a ref-counted data holder to ArrayBufferContents (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: type in ArrayBuffer::shareContentsWith Created 5 years, 6 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
Index: Source/wtf/ArrayBuffer.h
diff --git a/Source/wtf/ArrayBuffer.h b/Source/wtf/ArrayBuffer.h
index e8a737c8fcd3680cd6f5945a17a28713de15060a..a85d9e41a8afd3ffa40912ba5d56f2b4a68d7f53 100644
--- a/Source/wtf/ArrayBuffer.h
+++ b/Source/wtf/ArrayBuffer.h
@@ -50,6 +50,9 @@ public:
// (through DOMArrayBuffer::createUninitialized).
static inline PassRefPtr<ArrayBuffer> createUninitialized(unsigned numElements, unsigned elementByteSize);
+ static inline PassRefPtr<ArrayBuffer> createShared(unsigned numElements, unsigned elementByteSize);
+ static inline PassRefPtr<ArrayBuffer> createShared(const void* source, unsigned byteLength);
+
inline void* data();
inline const void* data() const;
inline unsigned byteLength() const;
@@ -63,7 +66,9 @@ public:
void removeView(ArrayBufferView*);
bool transfer(ArrayBufferContents&);
- bool isNeutered() { return m_isNeutered; }
+ bool shareContentsWith(ArrayBufferContents&);
+ bool isNeutered() const { return m_isNeutered; }
+ bool isShared() const { return m_contents.isShared(); }
~ArrayBuffer() { }
@@ -73,6 +78,7 @@ protected:
private:
static inline PassRefPtr<ArrayBuffer> create(unsigned numElements, unsigned elementByteSize, ArrayBufferContents::InitializationPolicy);
static inline PassRefPtr<ArrayBuffer> createOrNull(unsigned numElements, unsigned elementByteSize, ArrayBufferContents::InitializationPolicy);
+ static inline PassRefPtr<ArrayBuffer> createShared(unsigned numElements, unsigned elementByteSize, ArrayBufferContents::InitializationPolicy);
inline PassRefPtr<ArrayBuffer> sliceImpl(unsigned begin, unsigned end) const;
inline unsigned clampIndex(int index) const;
@@ -100,12 +106,14 @@ PassRefPtr<ArrayBuffer> ArrayBuffer::create(unsigned numElements, unsigned eleme
PassRefPtr<ArrayBuffer> ArrayBuffer::create(ArrayBuffer* other)
{
+ // TODO(binji): support creating a SharedArrayBuffer by copying another ArrayBuffer?
+ ASSERT(!other->isShared());
return ArrayBuffer::create(other->data(), other->byteLength());
}
PassRefPtr<ArrayBuffer> ArrayBuffer::create(const void* source, unsigned byteLength)
{
- ArrayBufferContents contents(byteLength, 1, ArrayBufferContents::ZeroInitialize);
+ ArrayBufferContents contents(byteLength, 1, ArrayBufferContents::NotShared, ArrayBufferContents::ZeroInitialize);
RELEASE_ASSERT(contents.data());
RefPtr<ArrayBuffer> buffer = adoptRef(new ArrayBuffer(contents));
memcpy(buffer->data(), source, byteLength);
@@ -129,19 +137,40 @@ PassRefPtr<ArrayBuffer> ArrayBuffer::createUninitialized(unsigned numElements, u
PassRefPtr<ArrayBuffer> ArrayBuffer::create(unsigned numElements, unsigned elementByteSize, ArrayBufferContents::InitializationPolicy policy)
{
- ArrayBufferContents contents(numElements, elementByteSize, policy);
+ ArrayBufferContents contents(numElements, elementByteSize, ArrayBufferContents::NotShared, policy);
RELEASE_ASSERT(contents.data());
return adoptRef(new ArrayBuffer(contents));
}
PassRefPtr<ArrayBuffer> ArrayBuffer::createOrNull(unsigned numElements, unsigned elementByteSize, ArrayBufferContents::InitializationPolicy policy)
{
- ArrayBufferContents contents(numElements, elementByteSize, policy);
+ ArrayBufferContents contents(numElements, elementByteSize, ArrayBufferContents::NotShared, policy);
if (!contents.data())
return nullptr;
return adoptRef(new ArrayBuffer(contents));
}
+PassRefPtr<ArrayBuffer> ArrayBuffer::createShared(unsigned numElements, unsigned elementByteSize)
+{
+ return createShared(numElements, elementByteSize, ArrayBufferContents::ZeroInitialize);
+}
+
+PassRefPtr<ArrayBuffer> ArrayBuffer::createShared(const void* source, unsigned byteLength)
+{
+ ArrayBufferContents contents(byteLength, 1, ArrayBufferContents::Shared, ArrayBufferContents::ZeroInitialize);
+ RELEASE_ASSERT(contents.data());
+ RefPtr<ArrayBuffer> buffer = adoptRef(new ArrayBuffer(contents));
+ memcpy(buffer->data(), source, byteLength);
+ return buffer.release();
+}
+
+PassRefPtr<ArrayBuffer> ArrayBuffer::createShared(unsigned numElements, unsigned elementByteSize, ArrayBufferContents::InitializationPolicy policy)
+{
+ ArrayBufferContents contents(numElements, elementByteSize, ArrayBufferContents::Shared, policy);
+ RELEASE_ASSERT(contents.data());
+ return adoptRef(new ArrayBuffer(contents));
+}
+
ArrayBuffer::ArrayBuffer(ArrayBufferContents& contents)
: m_firstView(0), m_isNeutered(false)
{

Powered by Google App Engine
This is Rietveld 408576698