OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef FlexibleArrayBufferView_h | |
6 #define FlexibleArrayBufferView_h | |
7 | |
8 #include "core/CoreExport.h" | |
9 #include "core/dom/DOMArrayBufferView.h" | |
10 #include "platform/heap/Handle.h" | |
11 #include "wtf/Noncopyable.h" | |
12 | |
13 namespace blink { | |
14 | |
15 // 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.
| |
16 // that is only valid during the life-time of the FlexibleArrayBufferView object . | |
17 | |
18 class CORE_EXPORT FlexibleArrayBufferView { | |
19 STACK_ALLOCATED(); | |
20 WTF_MAKE_NONCOPYABLE(FlexibleArrayBufferView); | |
21 public: | |
22 FlexibleArrayBufferView() | |
23 : m_smallData(nullptr) | |
24 , m_smallLength(0) | |
25 { | |
26 } | |
27 | |
28 void setFull(DOMArrayBufferView* full) { m_full = full; } | |
29 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.
| |
30 void clear() | |
31 { | |
32 m_full = nullptr; | |
33 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.
| |
34 } | |
35 | |
36 bool isEmpty() const { return !m_full && !m_smallData; } | |
37 | |
38 bool isFull() const { return m_full; } | |
39 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.
| |
40 | |
41 void* baseAddressMaybeOnStack() const { ASSERT(!isEmpty()); return isFull() ? m_full->baseAddress() : m_smallData; } | |
42 unsigned byteOffset() const { ASSERT(!isEmpty()); return isFull() ? m_full-> byteOffset() : 0; } | |
43 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.
| |
44 | |
45 operator bool() const { return !isEmpty(); } | |
46 | |
47 private: | |
48 RefPtr<DOMArrayBufferView> m_full; | |
49 | |
50 void* m_smallData; | |
51 size_t m_smallLength; | |
52 }; | |
53 | |
54 } // namespace blink | |
55 | |
56 #endif // FlexibleArrayBufferView_h | |
OLD | NEW |