OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 21 matching lines...) Expand all Loading... | |
32 #define ArrayBufferBuilder_h | 32 #define ArrayBufferBuilder_h |
33 | 33 |
34 #include "wtf/ArrayBuffer.h" | 34 #include "wtf/ArrayBuffer.h" |
35 #include "wtf/Noncopyable.h" | 35 #include "wtf/Noncopyable.h" |
36 #include "wtf/RefPtr.h" | 36 #include "wtf/RefPtr.h" |
37 #include "wtf/text/WTFString.h" | 37 #include "wtf/text/WTFString.h" |
38 | 38 |
39 namespace WTF { | 39 namespace WTF { |
40 | 40 |
41 // A utility class to build an ArrayBuffer instance. Validity must be checked | 41 // A utility class to build an ArrayBuffer instance. Validity must be checked |
42 // by isValid() before using an instance. | 42 // by isValid() before using an instance. |
binji
2015/10/16 22:12:39
hm, seems like a potentially dangerous interface.
Justin Novosad
2015/10/19 16:42:52
Potentially, but did you notice the 'isValid()' me
| |
43 class WTF_EXPORT ArrayBufferBuilder { | 43 class WTF_EXPORT ArrayBufferBuilder { |
44 // Disallow copying since it's expensive and we don't want code to do it by | 44 // Disallow copying since it's expensive and we don't want code to do it by |
45 // accident. | 45 // accident. |
46 WTF_MAKE_NONCOPYABLE(ArrayBufferBuilder); | 46 WTF_MAKE_NONCOPYABLE(ArrayBufferBuilder); |
47 | 47 |
48 public: | 48 public: |
49 // Creates an ArrayBufferBuilder using the default capacity. | 49 // Creates an ArrayBufferBuilder using the default capacity. |
50 ArrayBufferBuilder(); | 50 ArrayBufferBuilder(); |
51 | 51 |
52 ArrayBufferBuilder(unsigned capacity) | 52 ArrayBufferBuilder(unsigned capacity) |
53 : m_bytesUsed(0) | 53 : m_bytesUsed(0) |
54 , m_variableCapacity(true) | 54 , m_variableCapacity(true) |
55 { | 55 { |
56 m_buffer = ArrayBuffer::create(capacity, 1); | 56 m_buffer = ArrayBuffer::createOrNull(capacity, 1); |
57 } | 57 } |
58 | 58 |
59 bool isValid() const | 59 bool isValid() const |
60 { | 60 { |
61 return m_buffer; | 61 return m_buffer; |
62 } | 62 } |
63 | 63 |
64 // Appending empty data is not allowed. | 64 // Appending empty data is not allowed. |
65 unsigned append(const char* data, unsigned length); | 65 unsigned append(const char* data, unsigned length); |
66 | 66 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 unsigned m_bytesUsed; | 108 unsigned m_bytesUsed; |
109 bool m_variableCapacity; | 109 bool m_variableCapacity; |
110 RefPtr<ArrayBuffer> m_buffer; | 110 RefPtr<ArrayBuffer> m_buffer; |
111 }; | 111 }; |
112 | 112 |
113 } // namespace WTF | 113 } // namespace WTF |
114 | 114 |
115 using WTF::ArrayBufferBuilder; | 115 using WTF::ArrayBufferBuilder; |
116 | 116 |
117 #endif // ArrayBufferBuilder_h | 117 #endif // ArrayBufferBuilder_h |
OLD | NEW |