Index: src/string-builder.cc |
diff --git a/src/string-builder.cc b/src/string-builder.cc |
index c7488abb9513a29727f7e0877684343b03bbecad..7c46e0d523e41560ae633577850c2369b93bb608 100644 |
--- a/src/string-builder.cc |
+++ b/src/string-builder.cc |
@@ -55,25 +55,23 @@ IncrementalStringBuilder::IncrementalStringBuilder(Isolate* isolate) |
} |
-void IncrementalStringBuilder::Accumulate() { |
- // Only accumulate fully written strings. Shrink first if necessary. |
- DCHECK_EQ(current_index_, current_part()->length()); |
+void IncrementalStringBuilder::Accumulate(Handle<String> new_part) { |
Handle<String> new_accumulator; |
- if (accumulator()->length() + current_part()->length() > String::kMaxLength) { |
+ if (accumulator()->length() + new_part->length() > String::kMaxLength) { |
// Set the flag and carry on. Delay throwing the exception till the end. |
new_accumulator = factory()->empty_string(); |
overflowed_ = true; |
} else { |
- new_accumulator = factory() |
- ->NewConsString(accumulator(), current_part()) |
- .ToHandleChecked(); |
+ new_accumulator = |
+ factory()->NewConsString(accumulator(), new_part).ToHandleChecked(); |
} |
set_accumulator(new_accumulator); |
} |
void IncrementalStringBuilder::Extend() { |
- Accumulate(); |
+ DCHECK_EQ(current_index_, current_part()->length()); |
+ Accumulate(current_part()); |
if (part_length_ <= kMaxPartLength / kPartLengthGrowthFactor) { |
part_length_ *= kPartLengthGrowthFactor; |
} |
@@ -91,7 +89,7 @@ void IncrementalStringBuilder::Extend() { |
MaybeHandle<String> IncrementalStringBuilder::Finish() { |
ShrinkCurrentPart(); |
- Accumulate(); |
+ Accumulate(current_part()); |
if (overflowed_) { |
THROW_NEW_ERROR(isolate_, NewInvalidStringLengthError(), String); |
} |
@@ -103,9 +101,7 @@ void IncrementalStringBuilder::AppendString(Handle<String> string) { |
ShrinkCurrentPart(); |
part_length_ = kInitialPartLength; // Allocate conservatively. |
Extend(); // Attach current part and allocate new part. |
- Handle<String> concat = |
- factory()->NewConsString(accumulator(), string).ToHandleChecked(); |
- set_accumulator(concat); |
+ Accumulate(string); |
} |
} // namespace internal |
} // namespace v8 |