Skip to content

Commit

Permalink
Copy over the re2/ and util/ subdirectories.
Browse files Browse the repository at this point in the history
This change should fix the Bazel CI workflow; the GNU make and CMake
CI workflows will break now, but should be fixed by the next change.

Change-Id: I417463f0283cc74412789d68d1e8d5764d564e8c
Reviewed-on: https://code-review.googlesource.com/c/re2/+/61250
Reviewed-by: Alex Chernyakhovsky <achernya@google.com>
Reviewed-by: Paul Wankadia <junyer@google.com>
  • Loading branch information
junyer committed May 17, 2023
1 parent b76a3ea commit 49d776b
Show file tree
Hide file tree
Showing 75 changed files with 1,157 additions and 2,236 deletions.
8 changes: 4 additions & 4 deletions re2/bitmap256.cc
Expand Up @@ -6,7 +6,7 @@

#include <stdint.h>

#include "util/util.h"
#include "absl/base/macros.h"
#include "util/logging.h"

namespace re2 {
Expand All @@ -27,15 +27,15 @@ int Bitmap256::FindNextSetBit(int c) const {
case 1:
if (words_[1] != 0)
return (1 * 64) + FindLSBSet(words_[1]);
FALLTHROUGH_INTENDED;
ABSL_FALLTHROUGH_INTENDED;
case 2:
if (words_[2] != 0)
return (2 * 64) + FindLSBSet(words_[2]);
FALLTHROUGH_INTENDED;
ABSL_FALLTHROUGH_INTENDED;
case 3:
if (words_[3] != 0)
return (3 * 64) + FindLSBSet(words_[3]);
FALLTHROUGH_INTENDED;
ABSL_FALLTHROUGH_INTENDED;
default:
return -1;
}
Expand Down
46 changes: 21 additions & 25 deletions re2/bitstate.cc
Expand Up @@ -42,9 +42,8 @@ class BitState {

// The usual Search prototype.
// Can only call Search once per BitState.
bool Search(const StringPiece& text, const StringPiece& context,
bool anchored, bool longest,
StringPiece* submatch, int nsubmatch);
bool Search(absl::string_view text, absl::string_view context, bool anchored,
bool longest, absl::string_view* submatch, int nsubmatch);

private:
inline bool ShouldVisit(int id, const char* p);
Expand All @@ -53,14 +52,14 @@ class BitState {
bool TrySearch(int id, const char* p);

// Search parameters
Prog* prog_; // program being run
StringPiece text_; // text being searched
StringPiece context_; // greater context of text being searched
bool anchored_; // whether search is anchored at text.begin()
bool longest_; // whether search wants leftmost-longest match
bool endmatch_; // whether match must end at text.end()
StringPiece* submatch_; // submatches to fill in
int nsubmatch_; // # of submatches to fill in
Prog* prog_; // program being run
absl::string_view text_; // text being searched
absl::string_view context_; // greater context of text being searched
bool anchored_; // whether search is anchored at text.begin()
bool longest_; // whether search wants leftmost-longest match
bool endmatch_; // whether match must end at text.end()
absl::string_view* submatch_; // submatches to fill in
int nsubmatch_; // # of submatches to fill in

// Search state
static constexpr int kVisitedBits = 64;
Expand Down Expand Up @@ -256,9 +255,9 @@ bool BitState::TrySearch(int id0, const char* p0) {
if (submatch_[0].data() == NULL ||
(longest_ && p > submatch_[0].data() + submatch_[0].size())) {
for (int i = 0; i < nsubmatch_; i++)
submatch_[i] =
StringPiece(cap_[2 * i],
static_cast<size_t>(cap_[2 * i + 1] - cap_[2 * i]));
submatch_[i] = absl::string_view(
cap_[2 * i],
static_cast<size_t>(cap_[2 * i + 1] - cap_[2 * i]));
}

// If going for first match, we're done.
Expand All @@ -285,9 +284,9 @@ bool BitState::TrySearch(int id0, const char* p0) {
}

// Search text (within context) for prog_.
bool BitState::Search(const StringPiece& text, const StringPiece& context,
bool anchored, bool longest,
StringPiece* submatch, int nsubmatch) {
bool BitState::Search(absl::string_view text, absl::string_view context,
bool anchored, bool longest, absl::string_view* submatch,
int nsubmatch) {
// Search parameters.
text_ = text;
context_ = context;
Expand All @@ -303,7 +302,7 @@ bool BitState::Search(const StringPiece& text, const StringPiece& context,
submatch_ = submatch;
nsubmatch_ = nsubmatch;
for (int i = 0; i < nsubmatch_; i++)
submatch_[i] = StringPiece();
submatch_[i] = absl::string_view();

// Allocate scratch space.
int nvisited = prog_->list_count() * static_cast<int>(text.size()+1);
Expand Down Expand Up @@ -353,16 +352,13 @@ bool BitState::Search(const StringPiece& text, const StringPiece& context,
}

// Bit-state search.
bool Prog::SearchBitState(const StringPiece& text,
const StringPiece& context,
Anchor anchor,
MatchKind kind,
StringPiece* match,
int nmatch) {
bool Prog::SearchBitState(absl::string_view text, absl::string_view context,
Anchor anchor, MatchKind kind,
absl::string_view* match, int nmatch) {
// If full match, we ask for an anchored longest match
// and then check that match[0] == text.
// So make sure match[0] exists.
StringPiece sp0;
absl::string_view sp0;
if (kind == kFullMatch) {
anchor = kAnchored;
if (nmatch < 1) {
Expand Down
9 changes: 5 additions & 4 deletions re2/compile.cc
Expand Up @@ -10,9 +10,10 @@

#include <stdint.h>
#include <string.h>
#include <unordered_map>
#include <utility>

#include "absl/base/macros.h"
#include "absl/container/flat_hash_map.h"
#include "util/logging.h"
#include "util/utf.h"
#include "re2/pod_array.h"
Expand Down Expand Up @@ -211,7 +212,7 @@ class Compiler : public Regexp::Walker<Frag> {

int64_t max_mem_; // Total memory budget.

std::unordered_map<uint64_t, int> rune_cache_;
absl::flat_hash_map<uint64_t, int> rune_cache_;
Frag rune_range_;

RE2::Anchor anchor_; // anchor mode for RE2::Set
Expand Down Expand Up @@ -478,7 +479,7 @@ static uint64_t MakeRuneCacheKey(uint8_t lo, uint8_t hi, bool foldcase,
int Compiler::CachedRuneByteSuffix(uint8_t lo, uint8_t hi, bool foldcase,
int next) {
uint64_t key = MakeRuneCacheKey(lo, hi, foldcase, next);
std::unordered_map<uint64_t, int>::const_iterator it = rune_cache_.find(key);
absl::flat_hash_map<uint64_t, int>::const_iterator it = rune_cache_.find(key);
if (it != rune_cache_.end())
return it->second;
int id = UncachedRuneByteSuffix(lo, hi, foldcase, next);
Expand Down Expand Up @@ -1243,7 +1244,7 @@ Prog* Compiler::CompileSet(Regexp* re, RE2::Anchor anchor, int64_t max_mem) {
// Make sure DFA has enough memory to operate,
// since we're not going to fall back to the NFA.
bool dfa_failed = false;
StringPiece sp = "hello, world";
absl::string_view sp = "hello, world";
prog->SearchDFA(sp, sp, Prog::kAnchored, Prog::kManyMatch,
NULL, &dfa_failed, NULL);
if (dfa_failed) {
Expand Down

0 comments on commit 49d776b

Please sign in to comment.