Index: Source/core/dom/FlexibleArrayBufferView.h |
diff --git a/Source/core/dom/FlexibleArrayBufferView.h b/Source/core/dom/FlexibleArrayBufferView.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9defcedb4434b2aec5121215eeee078631b13610 |
--- /dev/null |
+++ b/Source/core/dom/FlexibleArrayBufferView.h |
@@ -0,0 +1,51 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef FlexibleArrayBufferView_h |
+#define FlexibleArrayBufferView_h |
+ |
+#include "core/CoreExport.h" |
+#include "core/dom/DOMArrayBufferView.h" |
+#include "platform/heap/Handle.h" |
+#include "wtf/Noncopyable.h" |
+ |
+namespace blink { |
+ |
+// WARNING: The pointer returned by baseAddress() may point to temporary storage |
+// that is only valid during the life-time of the FlexibleArrayBufferView object. |
haraken
2015/07/30 14:54:57
Just to confirm: Does the "life-time of the Flexib
Michael Lippautz
2015/07/30 17:06:15
Yes.
|
+ |
+class CORE_EXPORT FlexibleArrayBufferView { |
+ DISALLOW_ALLOCATION(); |
+ WTF_MAKE_NONCOPYABLE(FlexibleArrayBufferView); |
haraken
2015/07/30 14:54:57
Add WTF_MAKE_FAST_ALLOCATED().
Michael Lippautz
2015/07/30 17:06:15
Current use case is only stack allocated, so I gue
|
+public: |
+ FlexibleArrayBufferView() |
+ : m_smallData(nullptr), m_smallLength(0) |
jochen (gone - plz use gerrit)
2015/07/30 14:30:06
nit. each initializer on its own line:
: m_smallD
Michael Lippautz
2015/07/30 17:06:15
Done.
|
+ { |
+ } |
+ |
+ void setFull(DOMArrayBufferView* full) { m_full = full; } |
+ void setSmall(void* data, size_t length) { m_smallData = data; m_smallLength = length; } |
+ |
+ bool isEmpty() const { return !m_full && !m_smallData; } |
+ |
+ bool isFull() const { return m_full; } |
+ DOMArrayBufferView* full() const { ASSERT(isFull()); return m_full.get(); } |
+ |
+ void* baseAddress() const { ASSERT(!isEmpty()); return isFull() ? m_full->baseAddress() : m_smallData; } |
+ unsigned byteOffset() const { ASSERT(!isEmpty()); return isFull() ? m_full->byteOffset() : 0; } |
haraken
2015/07/30 14:54:57
Is it ok to return 0 for byteOffset()?
Michael Lippautz
2015/07/30 17:06:15
yes
|
+ unsigned byteLength() const { ASSERT(!isEmpty()); return isFull() ? m_full->byteLength() : m_smallLength; } |
+ |
+ operator bool() const { return !isEmpty(); } |
+ void operator= (std::nullptr_t) { m_full = nullptr; m_smallData = nullptr; } |
haraken
2015/07/30 14:54:57
We normally don't implement operator=(nullptr). It
Michael Lippautz
2015/07/30 17:06:15
Done.
|
+ |
+private: |
+ RefPtr<DOMArrayBufferView> m_full; |
+ |
+ void* m_smallData; |
+ size_t m_smallLength; |
+}; |
+ |
+} // namespace blink |
+ |
+#endif // FlexibleArrayBufferView_h |