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 #include "src/string-builder.h" | 5 #include "src/string-builder.h" |
6 | 6 |
7 #include "src/isolate-inl.h" | 7 #include "src/isolate-inl.h" |
8 #include "src/objects-inl.h" | 8 #include "src/objects-inl.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 } | 45 } |
46 | 46 |
47 | 47 |
48 IncrementalStringBuilder::IncrementalStringBuilder(Isolate* isolate) | 48 IncrementalStringBuilder::IncrementalStringBuilder(Isolate* isolate) |
49 : isolate_(isolate), | 49 : isolate_(isolate), |
50 encoding_(String::ONE_BYTE_ENCODING), | 50 encoding_(String::ONE_BYTE_ENCODING), |
51 overflowed_(false), | 51 overflowed_(false), |
52 part_length_(kInitialPartLength), | 52 part_length_(kInitialPartLength), |
53 current_index_(0) { | 53 current_index_(0) { |
54 // Create an accumulator handle starting with the empty string. | 54 // Create an accumulator handle starting with the empty string. |
55 accumulator_ = Handle<String>(isolate->heap()->empty_string(), isolate); | 55 accumulator_ = Handle<String>::New(isolate->heap()->empty_string(), isolate); |
56 current_part_ = | 56 current_part_ = |
57 factory()->NewRawOneByteString(part_length_).ToHandleChecked(); | 57 factory()->NewRawOneByteString(part_length_).ToHandleChecked(); |
58 } | 58 } |
59 | 59 |
60 | 60 |
61 void IncrementalStringBuilder::Accumulate(Handle<String> new_part) { | 61 void IncrementalStringBuilder::Accumulate(Handle<String> new_part) { |
62 Handle<String> new_accumulator; | 62 Handle<String> new_accumulator; |
63 if (accumulator()->length() + new_part->length() > String::kMaxLength) { | 63 if (accumulator()->length() + new_part->length() > String::kMaxLength) { |
64 // Set the flag and carry on. Delay throwing the exception till the end. | 64 // Set the flag and carry on. Delay throwing the exception till the end. |
65 new_accumulator = factory()->empty_string(); | 65 new_accumulator = factory()->empty_string(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 | 101 |
102 | 102 |
103 void IncrementalStringBuilder::AppendString(Handle<String> string) { | 103 void IncrementalStringBuilder::AppendString(Handle<String> string) { |
104 ShrinkCurrentPart(); | 104 ShrinkCurrentPart(); |
105 part_length_ = kInitialPartLength; // Allocate conservatively. | 105 part_length_ = kInitialPartLength; // Allocate conservatively. |
106 Extend(); // Attach current part and allocate new part. | 106 Extend(); // Attach current part and allocate new part. |
107 Accumulate(string); | 107 Accumulate(string); |
108 } | 108 } |
109 } // namespace internal | 109 } // namespace internal |
110 } // namespace v8 | 110 } // namespace v8 |
OLD | NEW |