Skip to content

Commit

Permalink
Merged: Check for encoding when appending in string builder
Browse files Browse the repository at this point in the history
Fixed: chromium:1450114
(cherry picked from commit a7e2bef)

Change-Id: I2c692c385def56a2ee07e5ae902200249e00d470
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4604097
Reviewed-by: Igor Sheludko <[email protected]>
Cr-Commit-Position: refs/branch-heads/11.5@{v8#8}
Cr-Branched-From: 0c4044b-refs/heads/11.5.150@{#1}
Cr-Branched-From: b71d303-refs/heads/main@{#87781}
  • Loading branch information
syg authored and jakobkummerow committed Jun 9, 2023
1 parent 84b0aff commit 06955cb
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/strings/string-builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,21 @@ bool IncrementalStringBuilder::CanAppendByCopy(Handle<String> string) {
void IncrementalStringBuilder::AppendStringByCopy(Handle<String> string) {
DCHECK(CanAppendByCopy(string));

Handle<SeqOneByteString> part =
Handle<SeqOneByteString>::cast(current_part());
{
DisallowGarbageCollection no_gc;
String::WriteToFlat(*string, part->GetChars(no_gc) + current_index_, 0,
string->length());
if (encoding_ == String::ONE_BYTE_ENCODING) {
String::WriteToFlat(
*string,
Handle<SeqOneByteString>::cast(current_part())->GetChars(no_gc) +
current_index_,
0, string->length());
} else {
String::WriteToFlat(
*string,
Handle<SeqTwoByteString>::cast(current_part())->GetChars(no_gc) +
current_index_,
0, string->length());
}
}
current_index_ += string->length();
DCHECK(current_index_ <= part_length_);
Expand Down

0 comments on commit 06955cb

Please sign in to comment.