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

Unified Diff: src/builtins/builtins-regexp.cc

Issue 2685183003: [regexp] Sticky handling in fast slow path (Closed)
Patch Set: Revert "Remove custom ToUint32" Created 3 years, 10 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 | src/runtime/runtime-regexp.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/builtins/builtins-regexp.cc
diff --git a/src/builtins/builtins-regexp.cc b/src/builtins/builtins-regexp.cc
index 2923cc2ba1a15b3a824b7b915c54d3c00af3f85d..0495548425f4343e90c936b979eb5b0fd6cb2c27 100644
--- a/src/builtins/builtins-regexp.cc
+++ b/src/builtins/builtins-regexp.cc
@@ -238,9 +238,6 @@ Node* RegExpBuiltinsAssembler::RegExpPrototypeExecBodyWithoutResult(
Variable var_result(this, MachineRepresentation::kTagged);
Label out(this);
- Node* const native_context = LoadNativeContext(context);
- Node* const string_length = LoadStringLength(string);
-
// Load lastIndex.
Variable var_lastindex(this, MachineRepresentation::kTagged);
{
@@ -282,6 +279,7 @@ Node* RegExpBuiltinsAssembler::RegExpPrototypeExecBodyWithoutResult(
Label if_isoob(this, Label::kDeferred);
GotoUnless(TaggedIsSmi(lastindex), &if_isoob);
+ Node* const string_length = LoadStringLength(string);
jgruber 2017/02/13 12:15:38 This and below are drive-by cleanups that push loa
GotoUnless(SmiLessThanOrEqual(lastindex, string_length), &if_isoob);
Goto(&run_exec);
@@ -305,6 +303,7 @@ Node* RegExpBuiltinsAssembler::RegExpPrototypeExecBodyWithoutResult(
Bind(&run_exec);
{
// Get last match info from the context.
+ Node* const native_context = LoadNativeContext(context);
Node* const last_match_info = LoadContextElement(
native_context, Context::REGEXP_LAST_MATCH_INFO_INDEX);
@@ -2337,9 +2336,6 @@ Node* RegExpBuiltinsAssembler::ReplaceSimpleStringFastPath(
// ToString({replace_value}) does not contain '$', i.e. we're doing a simple
// string replacement.
- Isolate* const isolate = this->isolate();
-
- Node* const null = NullConstant();
Node* const int_zero = IntPtrConstant(0);
Node* const smi_zero = SmiConstant(Smi::kZero);
@@ -2372,21 +2368,11 @@ Node* RegExpBuiltinsAssembler::ReplaceSimpleStringFastPath(
Bind(&if_isnonglobal);
{
// Run exec, then manually construct the resulting string.
- Callable exec_callable = CodeFactory::RegExpExec(isolate);
- Node* const match_indices = CallStub(exec_callable, context, regexp, string,
- smi_zero, last_match_info);
-
- Label if_matched(this), if_didnotmatch(this);
- Branch(WordEqual(match_indices, null), &if_didnotmatch, &if_matched);
-
- Bind(&if_didnotmatch);
- {
- FastStoreLastIndex(regexp, smi_zero);
- var_result.Bind(string);
- Goto(&out);
- }
+ Label if_didnotmatch(this);
+ Node* const match_indices = RegExpPrototypeExecBodyWithoutResult(
jgruber 2017/02/13 12:15:38 Replaced RE.p.exec emulation by inlined version of
+ context, regexp, string, &if_didnotmatch, true);
- Bind(&if_matched);
+ // Successful match.
{
Node* const subject_start = smi_zero;
Node* const match_start = LoadFixedArrayElement(
@@ -2430,6 +2416,12 @@ Node* RegExpBuiltinsAssembler::ReplaceSimpleStringFastPath(
Goto(&out);
}
}
+
+ Bind(&if_didnotmatch);
+ {
+ var_result.Bind(string);
+ Goto(&out);
+ }
}
Bind(&out);
@@ -2506,6 +2498,24 @@ TF_BUILTIN(RegExpPrototypeReplace, RegExpBuiltinsAssembler) {
Node* const replace_value = Parameter(2);
Node* const context = Parameter(5);
+ // RegExpPrototypeReplace is a bit of a beast - a summary of dispatch logic:
+ //
+ // if (!IsFastRegExp(receiver)) CallRuntime(RegExpReplace)
+ // if (IsCallable(replace)) {
+ // if (IsGlobal(receiver)) {
+ // // Called 'fast-path' but contains several runtime calls.
+ // ReplaceGlobalCallableFastPath()
+ // } else {
+ // CallRuntime(StringReplaceNonGlobalRegExpWithFunction)
+ // }
+ // } else {
+ // if (replace.contains("$")) {
+ // CallRuntime(RegExpReplace)
+ // } else {
+ // ReplaceSimpleStringFastPath() // Bails to runtime for global regexps.
+ // }
+ // }
+
// Ensure {maybe_receiver} is a JSReceiver.
Node* const map = ThrowIfNotJSReceiver(
context, maybe_receiver, MessageTemplate::kIncompatibleMethodReceiver,
« no previous file with comments | « no previous file | src/runtime/runtime-regexp.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698