mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Val: Switch TablePatternMatcher to std::string_view
...and add TableVal::LookupPattern(std::string_view sv).
This commit is contained in:
parent
dce51b99e5
commit
dad5ccd622
2 changed files with 18 additions and 9 deletions
20
src/Val.cc
20
src/Val.cc
|
@ -1573,10 +1573,10 @@ public:
|
||||||
|
|
||||||
void Clear() { matcher.reset(); }
|
void Clear() { matcher.reset(); }
|
||||||
|
|
||||||
VectorValPtr Lookup(const StringValPtr& s);
|
VectorValPtr Lookup(std::string_view sv);
|
||||||
|
|
||||||
// Delegate to matcher->MatchAll().
|
// Delegate to matcher->MatchAll().
|
||||||
bool MatchAll(const StringValPtr& s);
|
bool MatchAll(std::string_view sv);
|
||||||
|
|
||||||
void GetStats(detail::DFA_State_Cache_Stats* stats) const {
|
void GetStats(detail::DFA_State_Cache_Stats* stats) const {
|
||||||
if ( matcher && matcher->DFA() )
|
if ( matcher && matcher->DFA() )
|
||||||
|
@ -1606,7 +1606,7 @@ private:
|
||||||
std::vector<ValPtr> matcher_yields;
|
std::vector<ValPtr> matcher_yields;
|
||||||
};
|
};
|
||||||
|
|
||||||
VectorValPtr detail::TablePatternMatcher::Lookup(const StringValPtr& s) {
|
VectorValPtr detail::TablePatternMatcher::Lookup(std::string_view sv) {
|
||||||
auto results = make_intrusive<VectorVal>(vtype);
|
auto results = make_intrusive<VectorVal>(vtype);
|
||||||
|
|
||||||
if ( ! matcher ) {
|
if ( ! matcher ) {
|
||||||
|
@ -1617,7 +1617,7 @@ VectorValPtr detail::TablePatternMatcher::Lookup(const StringValPtr& s) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<AcceptIdx> matches;
|
std::vector<AcceptIdx> matches;
|
||||||
matcher->MatchSet(s->AsString(), matches);
|
matcher->MatchSet(sv, matches);
|
||||||
|
|
||||||
for ( auto m : matches )
|
for ( auto m : matches )
|
||||||
results->Append(matcher_yields[m]);
|
results->Append(matcher_yields[m]);
|
||||||
|
@ -1625,7 +1625,7 @@ VectorValPtr detail::TablePatternMatcher::Lookup(const StringValPtr& s) {
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool detail::TablePatternMatcher::MatchAll(const StringValPtr& s) {
|
bool detail::TablePatternMatcher::MatchAll(std::string_view sv) {
|
||||||
if ( ! matcher ) {
|
if ( ! matcher ) {
|
||||||
if ( tbl->Get()->Length() == 0 )
|
if ( tbl->Get()->Length() == 0 )
|
||||||
return false;
|
return false;
|
||||||
|
@ -1633,7 +1633,7 @@ bool detail::TablePatternMatcher::MatchAll(const StringValPtr& s) {
|
||||||
Build();
|
Build();
|
||||||
}
|
}
|
||||||
|
|
||||||
return matcher->MatchAll(s->AsString());
|
return matcher->MatchAll(sv);
|
||||||
}
|
}
|
||||||
|
|
||||||
void detail::TablePatternMatcher::Build() {
|
void detail::TablePatternMatcher::Build() {
|
||||||
|
@ -2182,18 +2182,20 @@ TableValPtr TableVal::LookupSubnetValues(const SubNetVal* search) {
|
||||||
return nt;
|
return nt;
|
||||||
}
|
}
|
||||||
|
|
||||||
VectorValPtr TableVal::LookupPattern(const StringValPtr& s) {
|
VectorValPtr TableVal::LookupPattern(const StringValPtr& s) { return LookupPattern(s->ToStdStringView()); }
|
||||||
|
|
||||||
|
VectorValPtr TableVal::LookupPattern(std::string_view sv) {
|
||||||
if ( ! pattern_matcher || ! GetType()->Yield() )
|
if ( ! pattern_matcher || ! GetType()->Yield() )
|
||||||
reporter->InternalError("LookupPattern called on wrong table type");
|
reporter->InternalError("LookupPattern called on wrong table type");
|
||||||
|
|
||||||
return pattern_matcher->Lookup(s);
|
return pattern_matcher->Lookup(sv);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TableVal::MatchPattern(const StringValPtr& s) {
|
bool TableVal::MatchPattern(const StringValPtr& s) {
|
||||||
if ( ! pattern_matcher )
|
if ( ! pattern_matcher )
|
||||||
reporter->InternalError("LookupPattern called on wrong table type");
|
reporter->InternalError("LookupPattern called on wrong table type");
|
||||||
|
|
||||||
return pattern_matcher->MatchAll(s);
|
return pattern_matcher->MatchAll(s->ToStdStringView());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TableVal::GetPatternMatcherStats(detail::DFA_State_Cache_Stats* stats) const {
|
void TableVal::GetPatternMatcherStats(detail::DFA_State_Cache_Stats* stats) const {
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
#include <sys/types.h> // for u_char
|
#include <sys/types.h> // for u_char
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
@ -898,6 +900,11 @@ public:
|
||||||
// Causes an internal error if called for any other kind of table.
|
// Causes an internal error if called for any other kind of table.
|
||||||
VectorValPtr LookupPattern(const StringValPtr& s);
|
VectorValPtr LookupPattern(const StringValPtr& s);
|
||||||
|
|
||||||
|
// For a table[pattern], return a vector of all yields matching
|
||||||
|
// the given string.
|
||||||
|
// Causes an internal error if called for any other kind of table.
|
||||||
|
VectorValPtr LookupPattern(std::string_view sv);
|
||||||
|
|
||||||
// For a table[pattern] or set[pattern], returns True if any of the
|
// For a table[pattern] or set[pattern], returns True if any of the
|
||||||
// patterns in the index matches the given string, else False.
|
// patterns in the index matches the given string, else False.
|
||||||
// Causes an internal error if called for any other kind of table.
|
// Causes an internal error if called for any other kind of table.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue