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

Side by Side Diff: third_party/WebKit/Source/wtf/ArrayPiece.cpp

Issue 1875343002: Move WTF classes related to typed arrays to wtf/typed_arrays (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 2014 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 #include "wtf/ArrayPiece.h"
6
7 #include "wtf/ArrayBuffer.h"
8 #include "wtf/ArrayBufferView.h"
9 #include "wtf/Assertions.h"
10
11 namespace WTF {
12
13 ArrayPiece::ArrayPiece()
14 {
15 initNull();
16 }
17
18 ArrayPiece::ArrayPiece(void* data, unsigned byteLength)
19 {
20 initWithData(data, byteLength);
21 }
22
23 ArrayPiece::ArrayPiece(ArrayBuffer* buffer)
24 {
25 if (buffer) {
26 initWithData(buffer->data(), buffer->byteLength());
27 } else {
28 initNull();
29 }
30 }
31
32 ArrayPiece::ArrayPiece(ArrayBufferView* buffer)
33 {
34 if (buffer) {
35 initWithData(buffer->baseAddress(), buffer->byteLength());
36 } else {
37 initNull();
38 }
39 }
40
41 bool ArrayPiece::isNull() const
42 {
43 return m_isNull;
44 }
45
46 void* ArrayPiece::data() const
47 {
48 ASSERT(!isNull());
49 return m_data;
50 }
51
52 unsigned char* ArrayPiece::bytes() const
53 {
54 return static_cast<unsigned char*>(data());
55 }
56
57 unsigned ArrayPiece::byteLength() const
58 {
59 ASSERT(!isNull());
60 return m_byteLength;
61 }
62
63 void ArrayPiece::initWithData(void* data, unsigned byteLength)
64 {
65 m_byteLength = byteLength;
66 m_data = data;
67 m_isNull = false;
68 }
69
70 void ArrayPiece::initNull()
71 {
72 m_byteLength = 0;
73 m_data = 0;
74 m_isNull = true;
75 }
76
77 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/ArrayPiece.h ('k') | third_party/WebKit/Source/wtf/Float32Array.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698