Commit 6498f8bb authored by Peter Marshall's avatar Peter Marshall Committed by Commit Bot

[regexp] Don't clone new JSRegExps when there is no feedback vector

When creating a new JSRegExp for a literal, we sometimes create a
boilerplate and store it in the feedback vector. Then for future
creations, we can copy the boilerplate instead of re-creating the
regexp from scratch.

When we don't have a feedback vector, we currently create a
boilerplate, copy it and return the copy, and then throw out the
boilerplate, which is unnecessary. We can just return the first
JSRegExp we create.

Change-Id: I98b4e3a3082654ea989e0e6ba1524ce080b0125c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1776086Reviewed-by: 's avatarSigurd Schneider <sigurds@chromium.org>
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63496}
parent 14243f12
...@@ -655,15 +655,16 @@ RUNTIME_FUNCTION(Runtime_CreateRegExpLiteral) { ...@@ -655,15 +655,16 @@ RUNTIME_FUNCTION(Runtime_CreateRegExpLiteral) {
DCHECK(maybe_vector->IsFeedbackVector()); DCHECK(maybe_vector->IsFeedbackVector());
vector = Handle<FeedbackVector>::cast(maybe_vector); vector = Handle<FeedbackVector>::cast(maybe_vector);
} }
Handle<Object> boilerplate;
if (vector.is_null()) { if (vector.is_null()) {
Handle<JSRegExp> new_regexp;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION( ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, boilerplate, isolate, new_regexp,
JSRegExp::New(isolate, pattern, JSRegExp::Flags(flags))); JSRegExp::New(isolate, pattern, JSRegExp::Flags(flags)));
return *JSRegExp::Copy(Handle<JSRegExp>::cast(boilerplate)); return *new_regexp;
} }
// Check if boilerplate exists. If not, create it first. // Check if boilerplate exists. If not, create it first.
Handle<JSRegExp> boilerplate;
Handle<Object> literal_site(vector->Get(literal_slot)->cast<Object>(), Handle<Object> literal_site(vector->Get(literal_slot)->cast<Object>(),
isolate); isolate);
if (!HasBoilerplate(literal_site)) { if (!HasBoilerplate(literal_site)) {
...@@ -676,7 +677,7 @@ RUNTIME_FUNCTION(Runtime_CreateRegExpLiteral) { ...@@ -676,7 +677,7 @@ RUNTIME_FUNCTION(Runtime_CreateRegExpLiteral) {
} }
vector->Set(literal_slot, *boilerplate); vector->Set(literal_slot, *boilerplate);
} }
return *JSRegExp::Copy(Handle<JSRegExp>::cast(boilerplate)); return *JSRegExp::Copy(boilerplate);
} }
} // namespace internal } // namespace internal
......
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