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

Unified Diff: src/jsregexp.cc

Issue 580383003: Reland sticky regexps https://codereview.chromium.org/567313003/ (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 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 | « src/jsregexp.h ('k') | src/objects.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/jsregexp.cc
diff --git a/src/jsregexp.cc b/src/jsregexp.cc
index ab2fb085db94a0c1f54c333bf148f034a742269a..98aca72665675665de9cebc86c1d8a7711e9fc8b 100644
--- a/src/jsregexp.cc
+++ b/src/jsregexp.cc
@@ -70,6 +70,9 @@ static JSRegExp::Flags RegExpFlagsFromString(Handle<String> str) {
case 'm':
flags |= JSRegExp::MULTILINE;
break;
+ case 'y':
+ if (FLAG_harmony_regexps) flags |= JSRegExp::STICKY;
+ break;
}
}
return JSRegExp::Flags(flags);
@@ -185,12 +188,14 @@ MaybeHandle<Object> RegExpImpl::Compile(Handle<JSRegExp> re,
if (parse_result.simple &&
!flags.is_ignore_case() &&
+ !flags.is_sticky() &&
!HasFewDifferentCharacters(pattern)) {
// Parse-tree is a single atom that is equal to the pattern.
AtomCompile(re, pattern, flags, pattern);
has_been_compiled = true;
} else if (parse_result.tree->IsAtom() &&
!flags.is_ignore_case() &&
+ !flags.is_sticky() &&
parse_result.capture_count == 0) {
RegExpAtom* atom = parse_result.tree->AsAtom();
Vector<const uc16> atom_pattern = atom->data();
@@ -430,7 +435,8 @@ bool RegExpImpl::CompileIrregexp(Handle<JSRegExp> re,
}
RegExpEngine::CompilationResult result = RegExpEngine::Compile(
&compile_data, flags.is_ignore_case(), flags.is_global(),
- flags.is_multiline(), pattern, sample_subject, is_one_byte, &zone);
+ flags.is_multiline(), flags.is_sticky(), pattern, sample_subject,
+ is_one_byte, &zone);
if (result.error_message != NULL) {
// Unable to compile regexp.
Handle<String> error_message = isolate->factory()->NewStringFromUtf8(
@@ -6027,8 +6033,8 @@ void DispatchTableConstructor::VisitAction(ActionNode* that) {
RegExpEngine::CompilationResult RegExpEngine::Compile(
RegExpCompileData* data, bool ignore_case, bool is_global,
- bool is_multiline, Handle<String> pattern, Handle<String> sample_subject,
- bool is_one_byte, Zone* zone) {
+ bool is_multiline, bool is_sticky, Handle<String> pattern,
+ Handle<String> sample_subject, bool is_one_byte, Zone* zone) {
if ((data->capture_count + 1) * 2 - 1 > RegExpMacroAssembler::kMaxRegister) {
return IrregexpRegExpTooBig(zone->isolate());
}
@@ -6055,9 +6061,9 @@ RegExpEngine::CompilationResult RegExpEngine::Compile(
bool is_end_anchored = data->tree->IsAnchoredAtEnd();
bool is_start_anchored = data->tree->IsAnchoredAtStart();
int max_length = data->tree->max_match();
- if (!is_start_anchored) {
+ if (!is_start_anchored && !is_sticky) {
// Add a .*? at the beginning, outside the body capture, unless
- // this expression is anchored at the beginning.
+ // this expression is anchored at the beginning or sticky.
RegExpNode* loop_node =
RegExpQuantifier::ToNode(0,
RegExpTree::kInfinity,
« no previous file with comments | « src/jsregexp.h ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698