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

Side by Side 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: Fixed typo Created 5 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 unified diff | Download patch
« no previous file with comments | « Source/core/core.gypi ('k') | Source/core/dom/TypedFlexibleArrayBufferView.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 class CORE_EXPORT FlexibleArrayBufferView {
16 STACK_ALLOCATED();
17 WTF_MAKE_NONCOPYABLE(FlexibleArrayBufferView);
18 public:
19 FlexibleArrayBufferView()
20 : m_smallData(nullptr)
21 , m_smallLength(0)
22 {
23 }
24
25 void setFull(DOMArrayBufferView* full) { m_full = full; }
26 void setSmall(void* data, size_t length)
27 {
28 m_smallData = data;
29 m_smallLength = length;
30 }
31
32 void clear()
33 {
34 m_full = nullptr;
35 m_smallData = nullptr;
36 m_smallLength = 0;
37 }
38
39 bool isEmpty() const { return !m_full && !m_smallData; }
40 bool isFull() const { return m_full; }
41
42 DOMArrayBufferView* full() const
43 {
44 ASSERT(isFull());
45 return m_full.get();
46 }
47
48 // WARNING: The pointer returned by baseAddressMaybeOnStack() may point to
49 // temporary storage that is only valid during the life-time of the
50 // FlexibleArrayBufferView object.
51 void* baseAddressMaybeOnStack() const
52 {
53 ASSERT(!isEmpty());
54 return isFull() ? m_full->baseAddress() : m_smallData;
55 }
56
57 unsigned byteOffset() const
58 {
59 ASSERT(!isEmpty());
60 return isFull() ? m_full->byteOffset() : 0;
61 }
62
63 unsigned byteLength() const
64 {
65 ASSERT(!isEmpty());
66 return isFull() ? m_full->byteLength() : m_smallLength;
67 }
68
69 operator bool() const { return !isEmpty(); }
70
71 private:
72 RefPtr<DOMArrayBufferView> m_full;
73
74 void* m_smallData;
75 size_t m_smallLength;
76 };
77
78 } // namespace blink
79
80 #endif // FlexibleArrayBufferView_h
OLDNEW
« no previous file with comments | « Source/core/core.gypi ('k') | Source/core/dom/TypedFlexibleArrayBufferView.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698