OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_STRING_STREAM_H_ | 5 #ifndef V8_STRING_STREAM_H_ |
6 #define V8_STRING_STREAM_H_ | 6 #define V8_STRING_STREAM_H_ |
7 | 7 |
8 #include "src/handles.h" | 8 #include "src/handles.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
11 namespace internal { | 11 namespace internal { |
12 | 12 |
13 class StringAllocator { | 13 class StringAllocator { |
14 public: | 14 public: |
15 virtual ~StringAllocator() { } | 15 virtual ~StringAllocator() { } |
16 // Allocate a number of bytes. | 16 // Allocate a number of bytes. |
17 virtual char* allocate(unsigned bytes) = 0; | 17 virtual char* allocate(unsigned bytes) = 0; |
18 // Allocate a larger number of bytes and copy the old buffer to the new one. | 18 // Allocate a larger number of bytes and copy the old buffer to the new one. |
19 // bytes is an input and output parameter passing the old size of the buffer | 19 // bytes is an input and output parameter passing the old size of the buffer |
20 // and returning the new size. If allocation fails then we return the old | 20 // and returning the new size. If allocation fails then we return the old |
21 // buffer and do not increase the size. | 21 // buffer and do not increase the size. |
22 virtual char* grow(unsigned* bytes) = 0; | 22 virtual char* grow(unsigned* bytes) = 0; |
23 }; | 23 }; |
24 | 24 |
25 | 25 |
26 // Normal allocator uses new[] and delete[]. | 26 // Normal allocator uses new[] and delete[]. |
27 class HeapStringAllocator FINAL : public StringAllocator { | 27 class HeapStringAllocator final : public StringAllocator { |
28 public: | 28 public: |
29 ~HeapStringAllocator() { DeleteArray(space_); } | 29 ~HeapStringAllocator() { DeleteArray(space_); } |
30 char* allocate(unsigned bytes) OVERRIDE; | 30 char* allocate(unsigned bytes) override; |
31 char* grow(unsigned* bytes) OVERRIDE; | 31 char* grow(unsigned* bytes) override; |
32 | 32 |
33 private: | 33 private: |
34 char* space_; | 34 char* space_; |
35 }; | 35 }; |
36 | 36 |
37 | 37 |
38 class FmtElm FINAL { | 38 class FmtElm final { |
39 public: | 39 public: |
40 FmtElm(int value) : type_(INT) { // NOLINT | 40 FmtElm(int value) : type_(INT) { // NOLINT |
41 data_.u_int_ = value; | 41 data_.u_int_ = value; |
42 } | 42 } |
43 explicit FmtElm(double value) : type_(DOUBLE) { | 43 explicit FmtElm(double value) : type_(DOUBLE) { |
44 data_.u_double_ = value; | 44 data_.u_double_ = value; |
45 } | 45 } |
46 FmtElm(const char* value) : type_(C_STR) { // NOLINT | 46 FmtElm(const char* value) : type_(C_STR) { // NOLINT |
47 data_.u_c_str_ = value; | 47 data_.u_c_str_ = value; |
48 } | 48 } |
(...skipping 19 matching lines...) Expand all Loading... |
68 double u_double_; | 68 double u_double_; |
69 const char* u_c_str_; | 69 const char* u_c_str_; |
70 const Vector<const uc16>* u_lc_str_; | 70 const Vector<const uc16>* u_lc_str_; |
71 Object* u_obj_; | 71 Object* u_obj_; |
72 Object** u_handle_; | 72 Object** u_handle_; |
73 void* u_pointer_; | 73 void* u_pointer_; |
74 } data_; | 74 } data_; |
75 }; | 75 }; |
76 | 76 |
77 | 77 |
78 class StringStream FINAL { | 78 class StringStream final { |
79 public: | 79 public: |
80 explicit StringStream(StringAllocator* allocator): | 80 explicit StringStream(StringAllocator* allocator): |
81 allocator_(allocator), | 81 allocator_(allocator), |
82 capacity_(kInitialCapacity), | 82 capacity_(kInitialCapacity), |
83 length_(0), | 83 length_(0), |
84 buffer_(allocator_->allocate(kInitialCapacity)) { | 84 buffer_(allocator_->allocate(kInitialCapacity)) { |
85 buffer_[0] = 0; | 85 buffer_[0] = 0; |
86 } | 86 } |
87 | 87 |
88 bool Put(char c); | 88 bool Put(char c); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 | 149 |
150 bool full() const { return (capacity_ - length_) == 1; } | 150 bool full() const { return (capacity_ - length_) == 1; } |
151 int space() const { return capacity_ - length_; } | 151 int space() const { return capacity_ - length_; } |
152 | 152 |
153 DISALLOW_IMPLICIT_CONSTRUCTORS(StringStream); | 153 DISALLOW_IMPLICIT_CONSTRUCTORS(StringStream); |
154 }; | 154 }; |
155 | 155 |
156 } } // namespace v8::internal | 156 } } // namespace v8::internal |
157 | 157 |
158 #endif // V8_STRING_STREAM_H_ | 158 #endif // V8_STRING_STREAM_H_ |
OLD | NEW |