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

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: 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
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 // WARNING: The pointer returned by baseAddress() may point to temporary storage
16 // 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.
17
18 class CORE_EXPORT FlexibleArrayBufferView {
19 DISALLOW_ALLOCATION();
20 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
21 public:
22 FlexibleArrayBufferView()
23 : 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.
24 {
25 }
26
27 void setFull(DOMArrayBufferView* full) { m_full = full; }
28 void setSmall(void* data, size_t length) { m_smallData = data; m_smallLength = length; }
29
30 bool isEmpty() const { return !m_full && !m_smallData; }
31
32 bool isFull() const { return m_full; }
33 DOMArrayBufferView* full() const { ASSERT(isFull()); return m_full.get(); }
34
35 void* baseAddress() const { ASSERT(!isEmpty()); return isFull() ? m_full->ba seAddress() : m_smallData; }
36 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
37 unsigned byteLength() const { ASSERT(!isEmpty()); return isFull() ? m_full-> byteLength() : m_smallLength; }
38
39 operator bool() const { return !isEmpty(); }
40 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.
41
42 private:
43 RefPtr<DOMArrayBufferView> m_full;
44
45 void* m_smallData;
46 size_t m_smallLength;
47 };
48
49 } // namespace blink
50
51 #endif // FlexibleArrayBufferView_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698