Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(481)

Unified Diff: src/runtime.cc

Issue 7839031: Fixing presubmit error. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixing one more issue. Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/mjsunit/string-replace.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index 7689a1acae5591abf2b23adba008e6d451675f4e..d66d67fe33c8db6c5fba17ca7003a782d163b990 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -2507,7 +2507,7 @@ class ReplacementStringBuilder {
class CompiledReplacement {
public:
CompiledReplacement()
- : parts_(1), replacement_substrings_(0) {}
+ : parts_(1), replacement_substrings_(0), simple_hint(false) {}
void Compile(Handle<String> replacement,
int capture_count,
@@ -2523,6 +2523,10 @@ class CompiledReplacement {
return parts_.length();
}
+ int IsSimple() {
Jakob Kummerow 2011/09/07 16:11:24 nit 1: This is C++. We have bools. nit 2: A simple
+ return simple_hint;
+ }
+
private:
enum PartType {
SUBJECT_PREFIX = 1,
@@ -2578,18 +2582,21 @@ class CompiledReplacement {
// Is replaced by REPLACEMENT_{SUB,}STRING when we create the
// substring objects.
int data;
+
};
template<typename Char>
- static void ParseReplacementPattern(ZoneList<ReplacementPart>* parts,
+ static bool ParseReplacementPattern(ZoneList<ReplacementPart>* parts,
Vector<Char> characters,
int capture_count,
int subject_length) {
int length = characters.length();
int last = 0;
+ bool simple = true;
for (int i = 0; i < length; i++) {
Char c = characters[i];
if (c == '$') {
+ simple = false;
int next_index = i + 1;
if (next_index == length) { // No next character!
break;
@@ -2682,10 +2689,12 @@ class CompiledReplacement {
parts->Add(ReplacementPart::ReplacementSubString(last, length));
}
}
+ return simple;
}
ZoneList<ReplacementPart> parts_;
ZoneList<Handle<String> > replacement_substrings_;
+ bool simple_hint;
Jakob Kummerow 2011/09/07 16:11:24 nit: trailing underscore please
};
@@ -2697,16 +2706,16 @@ void CompiledReplacement::Compile(Handle<String> replacement,
String::FlatContent content = replacement->GetFlatContent();
ASSERT(content.IsFlat());
if (content.IsAscii()) {
- ParseReplacementPattern(&parts_,
- content.ToAsciiVector(),
- capture_count,
- subject_length);
+ simple_hint = ParseReplacementPattern(&parts_,
+ content.ToAsciiVector(),
+ capture_count,
+ subject_length);
} else {
ASSERT(content.IsTwoByte());
- ParseReplacementPattern(&parts_,
- content.ToUC16Vector(),
- capture_count,
- subject_length);
+ simple_hint = ParseReplacementPattern(&parts_,
+ content.ToUC16Vector(),
+ capture_count,
+ subject_length);
}
}
Isolate* isolate = replacement->GetIsolate();
@@ -2901,7 +2910,7 @@ MUST_USE_RESULT static MaybeObject* StringReplaceStringWithString(
isolate->factory()->NewRawTwoByteString(result_len));
}
- for(int i = 0; i < matches; i++) {
+ for (int i = 0; i < matches; i++) {
// Copy non-matched subject content.
String::WriteToFlat(*subject,
result->GetChars() + result_pos,
@@ -2969,7 +2978,7 @@ MUST_USE_RESULT static MaybeObject* StringReplaceRegExpWithString(
// Shortcut for simple non-regexp global replacements
if (is_global &&
regexp->TypeTag() == JSRegExp::ATOM &&
- compiled_replacement.parts() == 1) {
+ compiled_replacement.IsSimple()) {
if (subject_handle->HasOnlyAsciiChars() &&
replacement_handle->HasOnlyAsciiChars()) {
return StringReplaceStringWithString<SeqAsciiString>(
« no previous file with comments | « no previous file | test/mjsunit/string-replace.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698