Skip to content

Commit 73da478

Browse files
iainirelandCommit Bot
authored andcommitted
[regexp] Remove function pointer in TextEmitPass
TextEmitPass uses a function pointer to determine which pass to call. This function pointer is only assigned inside TextEmitPass, and can easily be eliminated by moving the calls to each possible target inside the switch statement that assigns the function pointer. I made this change because SpiderMonkey uses a static analysis pass to verify that everything is rooted properly across calls that might GC, and that analysis is conservative when calling function pointers. We can white-list function pointers that are known to be safe, but the code being called through this function pointer is complex enough (and the function pointer is unnecessary enough) that it seemed best to just remove the function pointer entirely. R=jgruber@chromium.org Bug: v8:10303 Change-Id: I5fbb0df290a2288c4d3db6d43a563385337162ea Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2091398 Commit-Queue: Jakob Gruber <jgruber@chromium.org> Reviewed-by: Jakob Gruber <jgruber@chromium.org> Cr-Commit-Position: refs/heads/master@{#66672}
1 parent 025319b commit 73da478

1 file changed

Lines changed: 13 additions & 15 deletions

File tree

src/regexp/regexp-compiler.cc

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -862,10 +862,6 @@ static bool ShortCutEmitCharacterPair(RegExpMacroAssembler* macro_assembler,
862862
return false;
863863
}
864864

865-
using EmitCharacterFunction = bool(Isolate* isolate, RegExpCompiler* compiler,
866-
uc16 c, Label* on_failure, int cp_offset,
867-
bool check, bool preloaded);
868-
869865
// Only emits letters (things that have case). Only used for case independent
870866
// matches.
871867
static inline bool EmitAtomLetter(Isolate* isolate, RegExpCompiler* compiler,
@@ -2314,14 +2310,16 @@ void TextNode::TextEmitPass(RegExpCompiler* compiler, TextEmitPassType pass,
23142310
for (int j = preloaded ? 0 : quarks.length() - 1; j >= 0; j--) {
23152311
if (first_element_checked && i == 0 && j == 0) continue;
23162312
if (DeterminedAlready(quick_check, elm.cp_offset() + j)) continue;
2317-
EmitCharacterFunction* emit_function = nullptr;
23182313
uc16 quark = quarks[j];
23192314
if (elm.atom()->ignore_case()) {
23202315
// Everywhere else we assume that a non-Latin-1 character cannot match
23212316
// a Latin-1 character. Avoid the cases where this is assumption is
23222317
// invalid by using the Latin1 equivalent instead.
23232318
quark = unibrow::Latin1::TryConvertToLatin1(quark);
23242319
}
2320+
bool needs_bounds_check =
2321+
*checked_up_to < cp_offset + j || read_backward();
2322+
bool bounds_checked = false;
23252323
switch (pass) {
23262324
case NON_LATIN1_MATCH:
23272325
DCHECK(one_byte);
@@ -2331,24 +2329,24 @@ void TextNode::TextEmitPass(RegExpCompiler* compiler, TextEmitPassType pass,
23312329
}
23322330
break;
23332331
case NON_LETTER_CHARACTER_MATCH:
2334-
emit_function = &EmitAtomNonLetter;
2332+
bounds_checked =
2333+
EmitAtomNonLetter(isolate, compiler, quark, backtrack,
2334+
cp_offset + j, needs_bounds_check, preloaded);
23352335
break;
23362336
case SIMPLE_CHARACTER_MATCH:
2337-
emit_function = &EmitSimpleCharacter;
2337+
bounds_checked = EmitSimpleCharacter(isolate, compiler, quark,
2338+
backtrack, cp_offset + j,
2339+
needs_bounds_check, preloaded);
23382340
break;
23392341
case CASE_CHARACTER_MATCH:
2340-
emit_function = &EmitAtomLetter;
2342+
bounds_checked =
2343+
EmitAtomLetter(isolate, compiler, quark, backtrack,
2344+
cp_offset + j, needs_bounds_check, preloaded);
23412345
break;
23422346
default:
23432347
break;
23442348
}
2345-
if (emit_function != nullptr) {
2346-
bool bounds_check = *checked_up_to < cp_offset + j || read_backward();
2347-
bool bound_checked =
2348-
emit_function(isolate, compiler, quark, backtrack, cp_offset + j,
2349-
bounds_check, preloaded);
2350-
if (bound_checked) UpdateBoundsCheck(cp_offset + j, checked_up_to);
2351-
}
2349+
if (bounds_checked) UpdateBoundsCheck(cp_offset + j, checked_up_to);
23522350
}
23532351
} else {
23542352
DCHECK_EQ(TextElement::CHAR_CLASS, elm.text_type());

0 commit comments

Comments
 (0)