mirror of
https://github.com/zeek/zeek.git
synced 2025-10-10 02:28:21 +00:00
Refactor regex/signature AcceptingSet data structure and usages.
Several parts of that code would do membership checks and that's going to be more efficient with a set instead of a list data structure.
This commit is contained in:
parent
8126f06ffb
commit
171c6ce86b
5 changed files with 99 additions and 124 deletions
28
src/DFA.cc
28
src/DFA.cc
|
@ -211,9 +211,10 @@ void DFA_State::Dump(FILE* f, DFA_Machine* m)
|
|||
|
||||
if ( accept )
|
||||
{
|
||||
for ( int i = 0; i < accept->length(); ++i )
|
||||
fprintf(f, "%s accept #%d",
|
||||
i > 0 ? "," : "", int((*accept)[i]));
|
||||
AcceptingSet::const_iterator it;
|
||||
|
||||
for ( it = accept->begin(); it != accept->end(); ++it )
|
||||
fprintf(f, "%s accept #%d", it == accept->begin() ? "" : ",", *it);
|
||||
}
|
||||
|
||||
fprintf(f, "\n");
|
||||
|
@ -285,7 +286,7 @@ unsigned int DFA_State::Size()
|
|||
{
|
||||
return sizeof(*this)
|
||||
+ pad_size(sizeof(DFA_State*) * num_sym)
|
||||
+ (accept ? pad_size(sizeof(int) * accept->length()) : 0)
|
||||
+ (accept ? pad_size(sizeof(int) * accept->size()) : 0)
|
||||
+ (nfa_states ? pad_size(sizeof(NFA_State*) * nfa_states->length()) : 0)
|
||||
+ (meta_ec ? meta_ec->Size() : 0)
|
||||
+ (centry ? padded_sizeof(CacheEntry) : 0);
|
||||
|
@ -470,33 +471,20 @@ int DFA_Machine::StateSetToDFA_State(NFA_state_list* state_set,
|
|||
return 0;
|
||||
|
||||
AcceptingSet* accept = new AcceptingSet;
|
||||
|
||||
for ( int i = 0; i < state_set->length(); ++i )
|
||||
{
|
||||
int acc = (*state_set)[i]->Accept();
|
||||
|
||||
if ( acc != NO_ACCEPT )
|
||||
{
|
||||
int j;
|
||||
for ( j = 0; j < accept->length(); ++j )
|
||||
if ( (*accept)[j] == acc )
|
||||
break;
|
||||
|
||||
if ( j >= accept->length() )
|
||||
// It's not already present.
|
||||
accept->append(acc);
|
||||
}
|
||||
accept->insert(acc);
|
||||
}
|
||||
|
||||
if ( accept->length() == 0 )
|
||||
if ( accept->empty() )
|
||||
{
|
||||
delete accept;
|
||||
accept = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
accept->sort(int_list_cmp);
|
||||
accept->resize(0);
|
||||
}
|
||||
|
||||
DFA_State* ds = new DFA_State(state_count++, ec, state_set, accept);
|
||||
d = dfa_state_cache->Insert(ds, hash);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue