Amends to r9181 and r9191.

Review URL: http://codereview.chromium.org/7847019

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@9192 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
yangguo@chromium.org 2011-09-08 11:03:26 +00:00
parent 128552db35
commit 17d3f54b09
2 changed files with 24 additions and 24 deletions

View File

@ -4979,18 +4979,12 @@ void V8::RemoveMemoryAllocationCallback(MemoryAllocationCallback callback) {
void V8::PauseProfiler() { void V8::PauseProfiler() {
ApiCheck(i::FLAG_prof,
"V8::ResumeProfiler",
"Profiling has to be enabled with --prof");
i::Isolate* isolate = i::Isolate::Current(); i::Isolate* isolate = i::Isolate::Current();
isolate->logger()->PauseProfiler(); isolate->logger()->PauseProfiler();
} }
void V8::ResumeProfiler() { void V8::ResumeProfiler() {
ApiCheck(i::FLAG_prof,
"V8::ResumeProfiler",
"Profiling has to be enabled with --prof");
i::Isolate* isolate = i::Isolate::Current(); i::Isolate* isolate = i::Isolate::Current();
isolate->logger()->ResumeProfiler(); isolate->logger()->ResumeProfiler();
} }

View File

@ -2591,11 +2591,9 @@ class CompiledReplacement {
int subject_length) { int subject_length) {
int length = characters.length(); int length = characters.length();
int last = 0; int last = 0;
bool simple = true;
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
Char c = characters[i]; Char c = characters[i];
if (c == '$') { if (c == '$') {
simple = false;
int next_index = i + 1; int next_index = i + 1;
if (next_index == length) { // No next character! if (next_index == length) { // No next character!
break; break;
@ -2684,11 +2682,12 @@ class CompiledReplacement {
if (length > last) { if (length > last) {
if (last == 0) { if (last == 0) {
parts->Add(ReplacementPart::ReplacementString()); parts->Add(ReplacementPart::ReplacementString());
return true;
} else { } else {
parts->Add(ReplacementPart::ReplacementSubString(last, length)); parts->Add(ReplacementPart::ReplacementSubString(last, length));
} }
} }
return simple; return false;
} }
ZoneList<ReplacementPart> parts_; ZoneList<ReplacementPart> parts_;
@ -2879,17 +2878,18 @@ MUST_USE_RESULT static MaybeObject* StringReplaceStringWithString(
Isolate* isolate, Isolate* isolate,
Handle<String> subject, Handle<String> subject,
Handle<JSRegExp> pattern_regexp, Handle<JSRegExp> pattern_regexp,
Handle<String> replacement = Handle<String>::null()) { Handle<String> replacement) {
ASSERT(subject->IsFlat()); ASSERT(subject->IsFlat());
ASSERT(replacement.is_null() || replacement->IsFlat()); ASSERT(replacement->IsFlat());
ZoneScope zone_space(isolate, DELETE_ON_EXIT); ZoneScope zone_space(isolate, DELETE_ON_EXIT);
ZoneList<int> indices(8); ZoneList<int> indices(8);
ASSERT_EQ(JSRegExp::ATOM, pattern_regexp->TypeTag());
String* pattern = String* pattern =
String::cast(pattern_regexp->DataAt(JSRegExp::kAtomPatternIndex)); String::cast(pattern_regexp->DataAt(JSRegExp::kAtomPatternIndex));
int subject_len = subject->length(); int subject_len = subject->length();
int pattern_len = pattern->length(); int pattern_len = pattern->length();
int replacement_len = (replacement.is_null()) ? 0 : replacement->length(); int replacement_len = replacement->length();
FindStringIndicesDispatch(isolate, *subject, pattern, &indices, 0xffffffff); FindStringIndicesDispatch(isolate, *subject, pattern, &indices, 0xffffffff);
@ -2911,13 +2911,15 @@ MUST_USE_RESULT static MaybeObject* StringReplaceStringWithString(
for (int i = 0; i < matches; i++) { for (int i = 0; i < matches; i++) {
// Copy non-matched subject content. // Copy non-matched subject content.
if (subject_pos < indices.at(i)) {
String::WriteToFlat(*subject, String::WriteToFlat(*subject,
result->GetChars() + result_pos, result->GetChars() + result_pos,
subject_pos, subject_pos,
indices.at(i)); indices.at(i));
result_pos += indices.at(i) - subject_pos; result_pos += indices.at(i) - subject_pos;
// Replace match. }
// Replace match.
if (replacement_len > 0) { if (replacement_len > 0) {
String::WriteToFlat(*replacement, String::WriteToFlat(*replacement,
result->GetChars() + result_pos, result->GetChars() + result_pos,
@ -2928,10 +2930,13 @@ MUST_USE_RESULT static MaybeObject* StringReplaceStringWithString(
subject_pos = indices.at(i) + pattern_len; subject_pos = indices.at(i) + pattern_len;
} }
// Add remaining subject content at the end.
if (subject_pos < subject_len) {
String::WriteToFlat(*subject, String::WriteToFlat(*subject,
result->GetChars() + result_pos, result->GetChars() + result_pos,
subject_pos, subject_pos,
subject_len); subject_len);
}
return *result; return *result;
} }
@ -3077,12 +3082,13 @@ MUST_USE_RESULT static MaybeObject* StringReplaceRegExpWithEmptyString(
// Shortcut for simple non-regexp global replacements // Shortcut for simple non-regexp global replacements
if (regexp_handle->GetFlags().is_global() && if (regexp_handle->GetFlags().is_global() &&
regexp_handle->TypeTag() == JSRegExp::ATOM) { regexp_handle->TypeTag() == JSRegExp::ATOM) {
Handle<String> empty_string_handle(HEAP->empty_string());
if (subject_handle->HasOnlyAsciiChars()) { if (subject_handle->HasOnlyAsciiChars()) {
return StringReplaceStringWithString<SeqAsciiString>( return StringReplaceStringWithString<SeqAsciiString>(
isolate, subject_handle, regexp_handle); isolate, subject_handle, regexp_handle, empty_string_handle);
} else { } else {
return StringReplaceStringWithString<SeqTwoByteString>( return StringReplaceStringWithString<SeqTwoByteString>(
isolate, subject_handle, regexp_handle); isolate, subject_handle, regexp_handle, empty_string_handle);
} }
} }