| 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 virtual char* allocate(unsigned bytes) OVERRIDE; | 30 char* allocate(unsigned bytes) OVERRIDE; |
| 31 virtual 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; |
| (...skipping 107 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 |