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

Unified Diff: Source/core/dom/FlexibleArrayBufferView.h

Issue 1269443002: Introduce FlexibleArrayBufferView and TypedFlexibleArrayBufferView (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Addressed comments Created 5 years, 5 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/core/dom/FlexibleArrayBufferView.h
diff --git a/Source/core/dom/FlexibleArrayBufferView.h b/Source/core/dom/FlexibleArrayBufferView.h
new file mode 100644
index 0000000000000000000000000000000000000000..4dd13784af8bcf5ee24ebf1d83dd3e97cf22c159
--- /dev/null
+++ b/Source/core/dom/FlexibleArrayBufferView.h
@@ -0,0 +1,56 @@
+// 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
haraken 2015/07/30 20:34:44 baseAddress() => baseAddressMaybeOnStack() Move t
Michael Lippautz 2015/07/31 07:53:38 Done.
+// that is only valid during the life-time of the FlexibleArrayBufferView object.
+
+class CORE_EXPORT FlexibleArrayBufferView {
+ STACK_ALLOCATED();
+ WTF_MAKE_NONCOPYABLE(FlexibleArrayBufferView);
+public:
+ FlexibleArrayBufferView()
+ : m_smallData(nullptr)
+ , m_smallLength(0)
+ {
+ }
+
+ void setFull(DOMArrayBufferView* full) { m_full = full; }
+ void setSmall(void* data, size_t length) { m_smallData = data; m_smallLength = length; }
haraken 2015/07/30 20:34:44 Write sentences in separate lines.
Michael Lippautz 2015/07/31 07:53:38 Done.
+ void clear()
+ {
+ m_full = nullptr;
+ m_smallData = nullptr;
haraken 2015/07/30 20:34:44 m_smallLength = 0; just in case.
Michael Lippautz 2015/07/31 07:53:38 Done.
+ }
+
+ bool isEmpty() const { return !m_full && !m_smallData; }
+
+ bool isFull() const { return m_full; }
+ DOMArrayBufferView* full() const { ASSERT(isFull()); return m_full.get(); }
haraken 2015/07/30 20:34:44 Write sentences in separate lines.
Michael Lippautz 2015/07/31 07:53:38 Done.
+
+ void* baseAddressMaybeOnStack() const { ASSERT(!isEmpty()); return isFull() ? m_full->baseAddress() : m_smallData; }
+ unsigned byteOffset() const { ASSERT(!isEmpty()); return isFull() ? m_full->byteOffset() : 0; }
+ unsigned byteLength() const { ASSERT(!isEmpty()); return isFull() ? m_full->byteLength() : m_smallLength; }
haraken 2015/07/30 20:34:44 Ditto.
Michael Lippautz 2015/07/31 07:53:38 Done.
+
+ operator bool() const { return !isEmpty(); }
+
+private:
+ RefPtr<DOMArrayBufferView> m_full;
+
+ void* m_smallData;
+ size_t m_smallLength;
+};
+
+} // namespace blink
+
+#endif // FlexibleArrayBufferView_h

Powered by Google App Engine
This is Rietveld 408576698