MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / InlinedSearchLoop

Method InlinedSearchLoop

extern/re2/re2/dfa.cc:1323–1544  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1321 bool want_earliest_match,
1322 bool run_forward>
1323inline bool DFA::InlinedSearchLoop(SearchParams* params) {
1324 State* start = params->start;
1325 const uint8_t* bp = BytePtr(params->text.data()); // start of text
1326 const uint8_t* p = bp; // text scanning point
1327 const uint8_t* ep = BytePtr(params->text.data() +
1328 params->text.size()); // end of text
1329 const uint8_t* resetp = NULL; // p at last cache reset
1330 if (!run_forward) {
1331 using std::swap;
1332 swap(p, ep);
1333 }
1334
1335 const uint8_t* bytemap = prog_->bytemap();
1336 const uint8_t* lastmatch = NULL; // most recent matching position in text
1337 bool matched = false;
1338
1339 State* s = start;
1340 if (ExtraDebug)
1341 fprintf(stderr, "@stx: %s\n", DumpState(s).c_str());
1342
1343 if (s->IsMatch()) {
1344 matched = true;
1345 lastmatch = p;
1346 if (ExtraDebug)
1347 fprintf(stderr, "match @stx! [%s]\n", DumpState(s).c_str());
1348 if (params->matches != NULL && kind_ == Prog::kManyMatch) {
1349 for (int i = s->ninst_ - 1; i >= 0; i--) {
1350 int id = s->inst_[i];
1351 if (id == MatchSep)
1352 break;
1353 params->matches->insert(id);
1354 }
1355 }
1356 if (want_earliest_match) {
1357 params->ep = reinterpret_cast<const char*>(lastmatch);
1358 return true;
1359 }
1360 }
1361
1362 while (p != ep) {
1363 if (ExtraDebug)
1364 fprintf(stderr, "@%td: %s\n", p - bp, DumpState(s).c_str());
1365
1366 if (can_prefix_accel && s == start) {
1367 // In start state, only way out is to find the prefix,
1368 // so we use prefix accel (e.g. memchr) to skip ahead.
1369 // If not found, we can skip to the end of the string.
1370 p = BytePtr(prog_->PrefixAccel(p, ep - p));
1371 if (p == NULL) {
1372 p = ep;
1373 break;
1374 }
1375 }
1376
1377 int c;
1378 if (run_forward)
1379 c = *p++;
1380 else

Callers

nothing calls this directly

Calls 13

BytePtrFunction · 0.85
bytemapMethod · 0.80
IsMatchMethod · 0.80
PrefixAccelMethod · 0.80
RestoreMethod · 0.80
swapFunction · 0.50
dataMethod · 0.45
sizeMethod · 0.45
c_strMethod · 0.45
insertMethod · 0.45
loadMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected