Commit 2c2dd893 authored by Jakob Gruber's avatar Jakob Gruber Committed by Commit Bot

[regexp] Move AddRange utility function

Move this straggler to its use-site in regexp-compiler.cc.

Bug: v8:9359
Change-Id: Ia5393140de5a1c8d70ac410ef6239eabfec130b3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1662303
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Auto-Submit: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarPeter Marshall <petermarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62241}
parent a8c62102
...@@ -2521,6 +2521,31 @@ void BoyerMoorePositionInfo::Set(int character) { ...@@ -2521,6 +2521,31 @@ void BoyerMoorePositionInfo::Set(int character) {
SetInterval(Interval(character, character)); SetInterval(Interval(character, character));
} }
namespace {
ContainedInLattice AddRange(ContainedInLattice containment, const int* ranges,
int ranges_length, Interval new_range) {
DCHECK_EQ(1, ranges_length & 1);
DCHECK_EQ(String::kMaxCodePoint + 1, ranges[ranges_length - 1]);
if (containment == kLatticeUnknown) return containment;
bool inside = false;
int last = 0;
for (int i = 0; i < ranges_length; inside = !inside, last = ranges[i], i++) {
// Consider the range from last to ranges[i].
// We haven't got to the new range yet.
if (ranges[i] <= new_range.from()) continue;
// New range is wholly inside last-ranges[i]. Note that new_range.to() is
// inclusive, but the values in ranges are not.
if (last <= new_range.from() && new_range.to() < ranges[i]) {
return Combine(containment, inside ? kLatticeIn : kLatticeOut);
}
return kLatticeUnknown;
}
return containment;
}
} // namespace
void BoyerMoorePositionInfo::SetInterval(const Interval& interval) { void BoyerMoorePositionInfo::SetInterval(const Interval& interval) {
s_ = AddRange(s_, kSpaceRanges, kSpaceRangeCount, interval); s_ = AddRange(s_, kSpaceRanges, kSpaceRangeCount, interval);
w_ = AddRange(w_, kWordRanges, kWordRangeCount, interval); w_ = AddRange(w_, kWordRanges, kWordRangeCount, interval);
......
...@@ -277,9 +277,6 @@ inline ContainedInLattice Combine(ContainedInLattice a, ContainedInLattice b) { ...@@ -277,9 +277,6 @@ inline ContainedInLattice Combine(ContainedInLattice a, ContainedInLattice b) {
return static_cast<ContainedInLattice>(a | b); return static_cast<ContainedInLattice>(a | b);
} }
ContainedInLattice AddRange(ContainedInLattice a, const int* ranges,
int ranges_size, Interval new_range);
class BoyerMoorePositionInfo : public ZoneObject { class BoyerMoorePositionInfo : public ZoneObject {
public: public:
explicit BoyerMoorePositionInfo(Zone* zone) explicit BoyerMoorePositionInfo(Zone* zone)
......
...@@ -101,27 +101,6 @@ inline void ThrowRegExpException(Isolate* isolate, Handle<JSRegExp> re, ...@@ -101,27 +101,6 @@ inline void ThrowRegExpException(Isolate* isolate, Handle<JSRegExp> re,
error_text)); error_text));
} }
ContainedInLattice AddRange(ContainedInLattice containment, const int* ranges,
int ranges_length, Interval new_range) {
DCHECK_EQ(1, ranges_length & 1);
DCHECK_EQ(String::kMaxCodePoint + 1, ranges[ranges_length - 1]);
if (containment == kLatticeUnknown) return containment;
bool inside = false;
int last = 0;
for (int i = 0; i < ranges_length; inside = !inside, last = ranges[i], i++) {
// Consider the range from last to ranges[i].
// We haven't got to the new range yet.
if (ranges[i] <= new_range.from()) continue;
// New range is wholly inside last-ranges[i]. Note that new_range.to() is
// inclusive, but the values in ranges are not.
if (last <= new_range.from() && new_range.to() < ranges[i]) {
return Combine(containment, inside ? kLatticeIn : kLatticeOut);
}
return kLatticeUnknown;
}
return containment;
}
// Identifies the sort of regexps where the regexp engine is faster // Identifies the sort of regexps where the regexp engine is faster
// than the code used for atom matches. // than the code used for atom matches.
static bool HasFewDifferentCharacters(Handle<String> pattern) { static bool HasFewDifferentCharacters(Handle<String> pattern) {
......
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