Skip to content
Draft
37 changes: 27 additions & 10 deletions lib/Runtime/Library/RegexHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1941,16 +1941,33 @@ namespace Js
w = scriptContext->GetRegexDebugWriter();
#endif

pattern->rep.unified.matcher->Match
(state.input
, inputLength
, offset
, scriptContext
if (pattern->IsUnicode())
{
pattern->rep.unified.matcher->Match<true>
(state.input
, inputLength
, offset
, scriptContext
#if ENABLE_REGEX_CONFIG_OPTIONS
, stats
, w
, stats
, w
#endif
);
);
}
else
{
pattern->rep.unified.matcher->Match<false>
(state.input
, inputLength
, offset
, scriptContext
#if ENABLE_REGEX_CONFIG_OPTIONS
, stats
, w
#endif
);
}


#if ENABLE_REGEX_CONFIG_OPTIONS
if (REGEX_CONFIG_FLAG(RegexProfile))
Expand Down Expand Up @@ -2412,7 +2429,7 @@ namespace Js
{
if (string->GetLength() > (0 > index || (uint64_t)index + (uint64_t)1 > UINT32_MAX ? UINT32_MAX : (uint32_t)(index + 1)) &&
NumberUtilities::IsSurrogateLowerPart(string->GetString()[index]) &&
NumberUtilities::IsSurrogateUpperPart(string->GetString()[index + 1]))
NumberUtilities::IsSurrogateUpperPart(string->GetString()[index + 1]) && isUnicode)
Copy link
Collaborator

@rhuanjl rhuanjl Feb 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: ideally should do the isUnicode check first - it's much quicker, than the IsSurrogateLowerPart and IsSuurrogateUpperPart checks; if we do it first can skip the slower bits when it's false.

{
return index + 2;
}
Expand All @@ -2424,7 +2441,7 @@ namespace Js
{
if (string->GetLength() > index + 1 &&
NumberUtilities::IsSurrogateLowerPart(string->GetString()[index]) &&
NumberUtilities::IsSurrogateUpperPart(string->GetString()[index + 1]))
NumberUtilities::IsSurrogateUpperPart(string->GetString()[index + 1]) && isUnicode)
{
return JavascriptRegExp::AddIndex(index, 2);
}
Expand Down