From ab4d2b11c8bb977d2a108b2cdfc6fa5dbce44b93 Mon Sep 17 00:00:00 2001 From: yangguo Date: Tue, 18 Nov 2014 04:03:25 -0800 Subject: [PATCH] Use FlatStringReader in JSON stringifier. R=ishell@chromium.org Review URL: https://codereview.chromium.org/736543003 Cr-Commit-Position: refs/heads/master@{#25391} --- src/json-stringifier.h | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/json-stringifier.h b/src/json-stringifier.h index d28883f..4cdf31e 100644 --- a/src/json-stringifier.h +++ b/src/json-stringifier.h @@ -639,17 +639,9 @@ void BasicJsonStringifier::SerializeString_(Handle string) { &builder_, worst_case_length); SerializeStringUnchecked_(vector, &no_extend); } else { - String* string_location = NULL; - Vector vector(NULL, 0); - for (int i = 0; i < length; i++) { - // If GC moved the string, we need to refresh the vector. - if (*string != string_location) { - DisallowHeapAllocation no_gc; - // This does not actually prevent the string from being relocated later. - vector = GetCharVector(string); - string_location = *string; - } - SrcChar c = vector[i]; + FlatStringReader reader(isolate_, string); + for (int i = 0; i < reader.length(); i++) { + SrcChar c = static_cast(reader.Get(i)); if (DoNotEscape(c)) { builder_.Append(c); } else { -- 2.7.4