Commit 23635288 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[cleanup] Replace ZoneList in CompiledReplacement.

R=petermarshall@chromium.org
BUG=v8:7754

Change-Id: I44d5c808195b676c05f7d4837ad18cd33c377840
Reviewed-on: https://chromium-review.googlesource.com/1145067Reviewed-by: 's avatarPeter Marshall <petermarshall@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54584}
parent ff5cafd0
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "src/regexp/regexp-utils.h" #include "src/regexp/regexp-utils.h"
#include "src/string-builder.h" #include "src/string-builder.h"
#include "src/string-search.h" #include "src/string-search.h"
#include "src/zone/zone-chunk-list.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
...@@ -65,7 +66,7 @@ int LookupNamedCapture(std::function<bool(String*)> name_matches, ...@@ -65,7 +66,7 @@ int LookupNamedCapture(std::function<bool(String*)> name_matches,
class CompiledReplacement { class CompiledReplacement {
public: public:
explicit CompiledReplacement(Zone* zone) explicit CompiledReplacement(Zone* zone)
: parts_(1, zone), replacement_substrings_(0, zone), zone_(zone) {} : parts_(zone), replacement_substrings_(zone) {}
// Return whether the replacement is simple. // Return whether the replacement is simple.
bool Compile(Isolate* isolate, Handle<JSRegExp> regexp, bool Compile(Isolate* isolate, Handle<JSRegExp> regexp,
...@@ -77,9 +78,7 @@ class CompiledReplacement { ...@@ -77,9 +78,7 @@ class CompiledReplacement {
int32_t* match); int32_t* match);
// Number of distinct parts of the replacement pattern. // Number of distinct parts of the replacement pattern.
int parts() { return parts_.length(); } int parts() { return static_cast<int>(parts_.size()); }
Zone* zone() const { return zone_; }
private: private:
enum PartType { enum PartType {
...@@ -142,10 +141,10 @@ class CompiledReplacement { ...@@ -142,10 +141,10 @@ class CompiledReplacement {
}; };
template <typename Char> template <typename Char>
bool ParseReplacementPattern(ZoneList<ReplacementPart>* parts, bool ParseReplacementPattern(ZoneChunkList<ReplacementPart>* parts,
Vector<Char> characters, Vector<Char> characters,
FixedArray* capture_name_map, int capture_count, FixedArray* capture_name_map, int capture_count,
int subject_length, Zone* zone) { int subject_length) {
// Equivalent to String::GetSubstitution, except that this method converts // Equivalent to String::GetSubstitution, except that this method converts
// the replacement string into an internal representation that avoids // the replacement string into an internal representation that avoids
// repeated parsing when used repeatedly. // repeated parsing when used repeatedly.
...@@ -163,9 +162,8 @@ class CompiledReplacement { ...@@ -163,9 +162,8 @@ class CompiledReplacement {
case '$': case '$':
if (i > last) { if (i > last) {
// There is a substring before. Include the first "$". // There is a substring before. Include the first "$".
parts->Add( parts->push_back(
ReplacementPart::ReplacementSubString(last, next_index), ReplacementPart::ReplacementSubString(last, next_index));
zone);
last = next_index + 1; // Continue after the second "$". last = next_index + 1; // Continue after the second "$".
} else { } else {
// Let the next substring start with the second "$". // Let the next substring start with the second "$".
...@@ -175,25 +173,25 @@ class CompiledReplacement { ...@@ -175,25 +173,25 @@ class CompiledReplacement {
break; break;
case '`': case '`':
if (i > last) { if (i > last) {
parts->Add(ReplacementPart::ReplacementSubString(last, i), zone); parts->push_back(ReplacementPart::ReplacementSubString(last, i));
} }
parts->Add(ReplacementPart::SubjectPrefix(), zone); parts->push_back(ReplacementPart::SubjectPrefix());
i = next_index; i = next_index;
last = i + 1; last = i + 1;
break; break;
case '\'': case '\'':
if (i > last) { if (i > last) {
parts->Add(ReplacementPart::ReplacementSubString(last, i), zone); parts->push_back(ReplacementPart::ReplacementSubString(last, i));
} }
parts->Add(ReplacementPart::SubjectSuffix(subject_length), zone); parts->push_back(ReplacementPart::SubjectSuffix(subject_length));
i = next_index; i = next_index;
last = i + 1; last = i + 1;
break; break;
case '&': case '&':
if (i > last) { if (i > last) {
parts->Add(ReplacementPart::ReplacementSubString(last, i), zone); parts->push_back(ReplacementPart::ReplacementSubString(last, i));
} }
parts->Add(ReplacementPart::SubjectMatch(), zone); parts->push_back(ReplacementPart::SubjectMatch());
i = next_index; i = next_index;
last = i + 1; last = i + 1;
break; break;
...@@ -226,11 +224,11 @@ class CompiledReplacement { ...@@ -226,11 +224,11 @@ class CompiledReplacement {
} }
if (capture_ref > 0) { if (capture_ref > 0) {
if (i > last) { if (i > last) {
parts->Add(ReplacementPart::ReplacementSubString(last, i), parts->push_back(
zone); ReplacementPart::ReplacementSubString(last, i));
} }
DCHECK(capture_ref <= capture_count); DCHECK(capture_ref <= capture_count);
parts->Add(ReplacementPart::SubjectCapture(capture_ref), zone); parts->push_back(ReplacementPart::SubjectCapture(capture_ref));
last = next_index + 1; last = next_index + 1;
} }
i = next_index; i = next_index;
...@@ -281,12 +279,12 @@ class CompiledReplacement { ...@@ -281,12 +279,12 @@ class CompiledReplacement {
(1 <= capture_index && capture_index <= capture_count)); (1 <= capture_index && capture_index <= capture_count));
if (i > last) { if (i > last) {
parts->Add(ReplacementPart::ReplacementSubString(last, i), zone); parts->push_back(ReplacementPart::ReplacementSubString(last, i));
} }
parts->Add((capture_index == -1) parts->push_back(
? ReplacementPart::EmptyReplacement() (capture_index == -1)
: ReplacementPart::SubjectCapture(capture_index), ? ReplacementPart::EmptyReplacement()
zone); : ReplacementPart::SubjectCapture(capture_index));
last = closing_bracket_index + 1; last = closing_bracket_index + 1;
i = closing_bracket_index; i = closing_bracket_index;
break; break;
...@@ -302,15 +300,14 @@ class CompiledReplacement { ...@@ -302,15 +300,14 @@ class CompiledReplacement {
// Replacement is simple. Do not use Apply to do the replacement. // Replacement is simple. Do not use Apply to do the replacement.
return true; return true;
} else { } else {
parts->Add(ReplacementPart::ReplacementSubString(last, length), zone); parts->push_back(ReplacementPart::ReplacementSubString(last, length));
} }
} }
return false; return false;
} }
ZoneList<ReplacementPart> parts_; ZoneChunkList<ReplacementPart> parts_;
ZoneList<Handle<String> > replacement_substrings_; ZoneVector<Handle<String>> replacement_substrings_;
Zone* zone_;
}; };
bool CompiledReplacement::Compile(Isolate* isolate, Handle<JSRegExp> regexp, bool CompiledReplacement::Compile(Isolate* isolate, Handle<JSRegExp> regexp,
...@@ -334,31 +331,31 @@ bool CompiledReplacement::Compile(Isolate* isolate, Handle<JSRegExp> regexp, ...@@ -334,31 +331,31 @@ bool CompiledReplacement::Compile(Isolate* isolate, Handle<JSRegExp> regexp,
if (content.IsOneByte()) { if (content.IsOneByte()) {
simple = ParseReplacementPattern(&parts_, content.ToOneByteVector(), simple = ParseReplacementPattern(&parts_, content.ToOneByteVector(),
capture_name_map, capture_count, capture_name_map, capture_count,
subject_length, zone()); subject_length);
} else { } else {
DCHECK(content.IsTwoByte()); DCHECK(content.IsTwoByte());
simple = ParseReplacementPattern(&parts_, content.ToUC16Vector(), simple = ParseReplacementPattern(&parts_, content.ToUC16Vector(),
capture_name_map, capture_count, capture_name_map, capture_count,
subject_length, zone()); subject_length);
} }
if (simple) return true; if (simple) return true;
} }
// Find substrings of replacement string and create them as String objects. // Find substrings of replacement string and create them as String objects.
int substring_index = 0; int substring_index = 0;
for (int i = 0, n = parts_.length(); i < n; i++) { for (ReplacementPart& part : parts_) {
int tag = parts_[i].tag; int tag = part.tag;
if (tag <= 0) { // A replacement string slice. if (tag <= 0) { // A replacement string slice.
int from = -tag; int from = -tag;
int to = parts_[i].data; int to = part.data;
replacement_substrings_.Add( replacement_substrings_.push_back(
isolate->factory()->NewSubString(replacement, from, to), zone()); isolate->factory()->NewSubString(replacement, from, to));
parts_[i].tag = REPLACEMENT_SUBSTRING; part.tag = REPLACEMENT_SUBSTRING;
parts_[i].data = substring_index; part.data = substring_index;
substring_index++; substring_index++;
} else if (tag == REPLACEMENT_STRING) { } else if (tag == REPLACEMENT_STRING) {
replacement_substrings_.Add(replacement, zone()); replacement_substrings_.push_back(replacement);
parts_[i].data = substring_index; part.data = substring_index;
substring_index++; substring_index++;
} }
} }
...@@ -368,9 +365,8 @@ bool CompiledReplacement::Compile(Isolate* isolate, Handle<JSRegExp> regexp, ...@@ -368,9 +365,8 @@ bool CompiledReplacement::Compile(Isolate* isolate, Handle<JSRegExp> regexp,
void CompiledReplacement::Apply(ReplacementStringBuilder* builder, void CompiledReplacement::Apply(ReplacementStringBuilder* builder,
int match_from, int match_to, int32_t* match) { int match_from, int match_to, int32_t* match) {
DCHECK_LT(0, parts_.length()); DCHECK_LT(0, parts_.size());
for (int i = 0, n = parts_.length(); i < n; i++) { for (ReplacementPart& part : parts_) {
ReplacementPart part = parts_[i];
switch (part.tag) { switch (part.tag) {
case SUBJECT_PREFIX: case SUBJECT_PREFIX:
if (match_from > 0) builder->AddSubjectSlice(0, match_from); if (match_from > 0) builder->AddSubjectSlice(0, match_from);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment