Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
dart::BoyerMooreLookahead Class Reference

#include <regexp.h>

Inheritance diagram for dart::BoyerMooreLookahead:
dart::ZoneAllocated

Public Member Functions

 BoyerMooreLookahead (intptr_t length, RegExpCompiler *compiler, Zone *Zone)
 
intptr_t length ()
 
intptr_t max_char ()
 
RegExpCompilercompiler ()
 
intptr_t Count (intptr_t map_number)
 
BoyerMoorePositionInfoat (intptr_t i)
 
void Set (intptr_t map_number, intptr_t character)
 
void SetInterval (intptr_t map_number, const Interval &interval)
 
void SetAll (intptr_t map_number)
 
void SetRest (intptr_t from_map)
 
void EmitSkipInstructions (RegExpMacroAssembler *masm)
 
- Public Member Functions inherited from dart::ZoneAllocated
 ZoneAllocated ()
 
void * operator new (size_t size)
 
void * operator new (size_t size, Zone *zone)
 
void operator delete (void *pointer)
 

Detailed Description

Definition at line 1132 of file regexp.h.

Constructor & Destructor Documentation

◆ BoyerMooreLookahead()

dart::BoyerMooreLookahead::BoyerMooreLookahead ( intptr_t  length,
RegExpCompiler compiler,
Zone Zone 
)

Definition at line 2825 of file regexp.cc.

2828 : length_(length), compiler_(compiler) {
2829 if (compiler->one_byte()) {
2831 } else {
2832 max_char_ = Utf16::kMaxCodeUnit;
2833 }
2834 bitmaps_ = new (zone) ZoneGrowableArray<BoyerMoorePositionInfo*>(length);
2835 for (intptr_t i = 0; i < length; i++) {
2836 bitmaps_->Add(new (zone) BoyerMoorePositionInfo(zone));
2837 }
2838}
@ kMaxOneCharCodeSymbol
Definition: symbols.h:577
static constexpr int32_t kMaxCodeUnit
Definition: unicode.h:158

Member Function Documentation

◆ at()

BoyerMoorePositionInfo * dart::BoyerMooreLookahead::at ( intptr_t  i)
inline

Definition at line 1144 of file regexp.h.

1144{ return bitmaps_->At(i); }

◆ compiler()

RegExpCompiler * dart::BoyerMooreLookahead::compiler ( )
inline

Definition at line 1138 of file regexp.h.

1138{ return compiler_; }

◆ Count()

intptr_t dart::BoyerMooreLookahead::Count ( intptr_t  map_number)
inline

Definition at line 1140 of file regexp.h.

1140 {
1141 return bitmaps_->At(map_number)->map_count();
1142 }

◆ EmitSkipInstructions()

void dart::BoyerMooreLookahead::EmitSkipInstructions ( RegExpMacroAssembler masm)

Definition at line 2948 of file regexp.cc.

2948 {
2949 const intptr_t kSize = RegExpMacroAssembler::kTableSize;
2950
2951 intptr_t min_lookahead = 0;
2952 intptr_t max_lookahead = 0;
2953
2954 if (!FindWorthwhileInterval(&min_lookahead, &max_lookahead)) return;
2955
2956 bool found_single_character = false;
2957 intptr_t single_character = 0;
2958 for (intptr_t i = max_lookahead; i >= min_lookahead; i--) {
2959 BoyerMoorePositionInfo* map = bitmaps_->At(i);
2960 if (map->map_count() > 1 ||
2961 (found_single_character && map->map_count() != 0)) {
2962 found_single_character = false;
2963 break;
2964 }
2965 for (intptr_t j = 0; j < kSize; j++) {
2966 if (map->at(j)) {
2967 found_single_character = true;
2968 single_character = j;
2969 break;
2970 }
2971 }
2972 }
2973
2974 intptr_t lookahead_width = max_lookahead + 1 - min_lookahead;
2975
2976 if (found_single_character && lookahead_width == 1 && max_lookahead < 3) {
2977 // The mask-compare can probably handle this better.
2978 return;
2979 }
2980
2981 if (found_single_character) {
2982 BlockLabel cont, again;
2983 masm->BindBlock(&again);
2984 masm->LoadCurrentCharacter(max_lookahead, &cont, true);
2985 if (max_char_ > kSize) {
2986 masm->CheckCharacterAfterAnd(single_character,
2988 } else {
2989 masm->CheckCharacter(single_character, &cont);
2990 }
2991 masm->AdvanceCurrentPosition(lookahead_width);
2992 masm->GoTo(&again);
2993 masm->BindBlock(&cont);
2994 return;
2995 }
2996
2997 const TypedData& boolean_skip_table = TypedData::ZoneHandle(
2998 compiler_->zone(),
2999 TypedData::New(kTypedDataUint8ArrayCid, kSize, Heap::kOld));
3000 intptr_t skip_distance =
3001 GetSkipTable(min_lookahead, max_lookahead, boolean_skip_table);
3002 ASSERT(skip_distance != 0);
3003
3004 BlockLabel cont, again;
3005
3006 masm->BindBlock(&again);
3007 masm->CheckPreemption(/*is_backtrack=*/false);
3008 masm->LoadCurrentCharacter(max_lookahead, &cont, true);
3009 masm->CheckBitInTable(boolean_skip_table, &cont);
3010 masm->AdvanceCurrentPosition(skip_distance);
3011 masm->GoTo(&again);
3012 masm->BindBlock(&cont);
3013
3014 return;
3015}
@ kOld
Definition: heap.h:39
static Object & ZoneHandle()
Definition: object.h:419
Zone * zone() const
Definition: regexp.cc:353
static constexpr intptr_t kTableMask
static constexpr intptr_t kTableSize
static TypedDataPtr New(intptr_t class_id, intptr_t len, Heap::Space space=Heap::kNew)
Definition: object.cc:25587
#define ASSERT(E)
constexpr SkISize kSize
Definition: mock_canvas.cc:17
SI auto map(std::index_sequence< I... >, Fn &&fn, const Args &... args) -> skvx::Vec< sizeof...(I), decltype(fn(args[0]...))>
Definition: SkVx.h:680

◆ length()

intptr_t dart::BoyerMooreLookahead::length ( )
inline

Definition at line 1136 of file regexp.h.

1136{ return length_; }

◆ max_char()

intptr_t dart::BoyerMooreLookahead::max_char ( )
inline

Definition at line 1137 of file regexp.h.

1137{ return max_char_; }

◆ Set()

void dart::BoyerMooreLookahead::Set ( intptr_t  map_number,
intptr_t  character 
)
inline

Definition at line 1146 of file regexp.h.

1146 {
1147 if (character > max_char_) return;
1148 BoyerMoorePositionInfo* info = bitmaps_->At(map_number);
1149 info->Set(character);
1150 }
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213

◆ SetAll()

void dart::BoyerMooreLookahead::SetAll ( intptr_t  map_number)
inline

Definition at line 1162 of file regexp.h.

1162{ bitmaps_->At(map_number)->SetAll(); }

◆ SetInterval()

void dart::BoyerMooreLookahead::SetInterval ( intptr_t  map_number,
const Interval interval 
)
inline

Definition at line 1152 of file regexp.h.

1152 {
1153 if (interval.from() > max_char_) return;
1154 BoyerMoorePositionInfo* info = bitmaps_->At(map_number);
1155 if (interval.to() > max_char_) {
1156 info->SetInterval(Interval(interval.from(), max_char_));
1157 } else {
1158 info->SetInterval(interval);
1159 }
1160 }

◆ SetRest()

void dart::BoyerMooreLookahead::SetRest ( intptr_t  from_map)
inline

Definition at line 1164 of file regexp.h.

1164 {
1165 for (intptr_t i = from_map; i < length_; i++)
1166 SetAll(i);
1167 }
void SetAll(intptr_t map_number)
Definition: regexp.h:1162

The documentation for this class was generated from the following files: