Merge remote-tracking branch 'origin/topic/timw/analyzer-iterators'

- During merge, simplified the API docs for Analyzer::DeleteChild()
  (found it unclear/unnecessary to refer to any `std` container types)

* origin/topic/timw/analyzer-iterators:
  Clean up iterator usage in Analyzer
This commit is contained in:
Jon Siwek 2021-03-23 16:27:27 -07:00
commit fd7402e8d6
6 changed files with 47 additions and 35 deletions

10
CHANGES
View file

@ -1,3 +1,13 @@
4.1.0-dev.344 | 2021-03-23 16:29:27 -0700
* Clean up iterator usage in Analyzer (Tim Wojtulewicz, Corelight)
The ``zeek::analyzer::analyzer_list`` type-alias changed from an
``std::list`` to ``std::vector`` which, in practice, is not expected to be
used from plugins in API-incompatible way and may result in ~1-2% overall
performance benefit.
4.1.0-dev.341 | 2021-03-18 12:45:04 -0700 4.1.0-dev.341 | 2021-03-18 12:45:04 -0700
* fix for associating current scope with the name of enums; name tidying (Vern Paxson, Corelight) * fix for associating current scope with the name of enums; name tidying (Vern Paxson, Corelight)

5
NEWS
View file

@ -49,6 +49,11 @@ New Functionality
Changed Functionality Changed Functionality
--------------------- ---------------------
- The ``zeek::analyzer::analyzer_list`` type-alias changed from an
``std::list`` to ``std::vector`` which, in practice, is not expected to be
used from plugins in API-incompatible way and may result in ~1-2% overall
performance benefit.
Removed Functionality Removed Functionality
--------------------- ---------------------

View file

@ -1 +1 @@
4.1.0-dev.341 4.1.0-dev.344

View file

@ -301,17 +301,17 @@ void Analyzer::ForwardPacket(int len, const u_char* data, bool is_orig,
AppendNewChildren(); AppendNewChildren();
// Pass to all children. // Pass to all children.
analyzer_list::iterator next; for ( auto i = children.begin(); i != children.end(); )
for ( analyzer_list::iterator i = children.begin();
i != children.end(); i = next )
{ {
Analyzer* current = *i; Analyzer* current = *i;
next = ++i;
if ( ! (current->finished || current->removing ) ) if ( ! (current->finished || current->removing ) )
{
current->NextPacket(len, data, is_orig, seq, ip, caplen); current->NextPacket(len, data, is_orig, seq, ip, caplen);
++i;
}
else else
DeleteChild(--i); i = DeleteChild(i);
} }
AppendNewChildren(); AppendNewChildren();
@ -324,17 +324,17 @@ void Analyzer::ForwardStream(int len, const u_char* data, bool is_orig)
AppendNewChildren(); AppendNewChildren();
analyzer_list::iterator next; for ( auto i = children.begin(); i != children.end(); )
for ( analyzer_list::iterator i = children.begin();
i != children.end(); i = next )
{ {
Analyzer* current = *i; Analyzer* current = *i;
next = ++i;
if ( ! (current->finished || current->removing ) ) if ( ! (current->finished || current->removing ) )
{
current->NextStream(len, data, is_orig); current->NextStream(len, data, is_orig);
++i;
}
else else
DeleteChild(--i); i = DeleteChild(i);
} }
AppendNewChildren(); AppendNewChildren();
@ -347,17 +347,17 @@ void Analyzer::ForwardUndelivered(uint64_t seq, int len, bool is_orig)
AppendNewChildren(); AppendNewChildren();
analyzer_list::iterator next; for ( auto i = children.begin(); i != children.end(); )
for ( analyzer_list::iterator i = children.begin();
i != children.end(); i = next )
{ {
Analyzer* current = *i; Analyzer* current = *i;
next = ++i;
if ( ! (current->finished || current->removing ) ) if ( ! (current->finished || current->removing ) )
{
current->NextUndelivered(seq, len, is_orig); current->NextUndelivered(seq, len, is_orig);
++i;
}
else else
DeleteChild(--i); i = DeleteChild(i);
} }
AppendNewChildren(); AppendNewChildren();
@ -367,17 +367,17 @@ void Analyzer::ForwardEndOfData(bool orig)
{ {
AppendNewChildren(); AppendNewChildren();
analyzer_list::iterator next; for ( auto i = children.begin(); i != children.end(); )
for ( analyzer_list::iterator i = children.begin();
i != children.end(); i = next )
{ {
Analyzer* current = *i; Analyzer* current = *i;
next = ++i;
if ( ! (current->finished || current->removing ) ) if ( ! (current->finished || current->removing ) )
{
current->NextEndOfData(orig); current->NextEndOfData(orig);
++i;
}
else else
DeleteChild(--i); i = DeleteChild(i);
} }
AppendNewChildren(); AppendNewChildren();
@ -541,7 +541,7 @@ Analyzer* Analyzer::FindChild(const char* name)
return tag ? FindChild(tag) : nullptr; return tag ? FindChild(tag) : nullptr;
} }
void Analyzer::DeleteChild(analyzer_list::iterator i) analyzer_list::iterator Analyzer::DeleteChild(analyzer_list::iterator i)
{ {
Analyzer* child = *i; Analyzer* child = *i;
@ -557,8 +557,9 @@ void Analyzer::DeleteChild(analyzer_list::iterator i)
DBG_LOG(DBG_ANALYZER, "%s deleted child %s 3", DBG_LOG(DBG_ANALYZER, "%s deleted child %s 3",
fmt_analyzer(this).c_str(), fmt_analyzer(child).c_str()); fmt_analyzer(this).c_str(), fmt_analyzer(child).c_str());
children.erase(i); auto next = children.erase(i);
delete child; delete child;
return next;
} }
void Analyzer::AddSupportAnalyzer(SupportAnalyzer* analyzer) void Analyzer::AddSupportAnalyzer(SupportAnalyzer* analyzer)

View file

@ -38,7 +38,7 @@ class AnalyzerTimer;
class SupportAnalyzer; class SupportAnalyzer;
class OutputHandler; class OutputHandler;
using analyzer_list = std::list<Analyzer*>; using analyzer_list = std::vector<Analyzer*>;
typedef uint32_t ID; typedef uint32_t ID;
typedef void (Analyzer::*analyzer_timer_func)(double t); typedef void (Analyzer::*analyzer_timer_func)(double t);
@ -685,8 +685,9 @@ protected:
private: private:
// Internal method to eventually delete a child analyzer that's // Internal method to eventually delete a child analyzer that's
// already Done(). // already Done(). Returns an iterator pointing to the next element after
void DeleteChild(analyzer_list::iterator i); // the just-removed element.
analyzer_list::iterator DeleteChild(analyzer_list::iterator i);
// Helper for the ctors. // Helper for the ctors.
void CtorInit(const Tag& tag, Connection* conn); void CtorInit(const Tag& tag, Connection* conn);
@ -727,31 +728,27 @@ private:
* Internal convenience macro to iterate over the list of child analyzers. * Internal convenience macro to iterate over the list of child analyzers.
*/ */
#define LOOP_OVER_CHILDREN(var) \ #define LOOP_OVER_CHILDREN(var) \
for ( zeek::analyzer::analyzer_list::iterator var = children.begin(); \ for ( auto var = children.begin(); var != children.end(); ++var )
var != children.end(); var++ )
/** /**
* Internal convenience macro to iterate over the constant list of child * Internal convenience macro to iterate over the constant list of child
* analyzers. * analyzers.
*/ */
#define LOOP_OVER_CONST_CHILDREN(var) \ #define LOOP_OVER_CONST_CHILDREN(var) \
for ( zeek::analyzer::analyzer_list::const_iterator var = children.begin(); \ for ( auto var = children.cbegin(); var != children.cend(); ++var )
var != children.end(); var++ )
/** /**
* Convenience macro to iterate over a given list of child analyzers. * Convenience macro to iterate over a given list of child analyzers.
*/ */
#define LOOP_OVER_GIVEN_CHILDREN(var, the_kids) \ #define LOOP_OVER_GIVEN_CHILDREN(var, the_kids) \
for ( zeek::analyzer::analyzer_list::iterator var = the_kids.begin(); \ for ( auto var = the_kids.begin(); var != the_kids.end(); ++var )
var != the_kids.end(); var++ )
/** /**
* Convenience macro to iterate over a given constant list of child * Convenience macro to iterate over a given constant list of child
* analyzers. * analyzers.
*/ */
#define LOOP_OVER_GIVEN_CONST_CHILDREN(var, the_kids) \ #define LOOP_OVER_GIVEN_CONST_CHILDREN(var, the_kids) \
for ( zeek::analyzer::analyzer_list::const_iterator var = the_kids.begin(); \ for ( auto var = the_kids.cbegin(); var != the_kids.cend(); ++var )
var != the_kids.end(); var++ )
/** /**
* Support analyzer preprocess input before it reaches an analyzer's main * Support analyzer preprocess input before it reaches an analyzer's main

View file

@ -174,7 +174,6 @@ private:
TCP_Endpoint* orig; TCP_Endpoint* orig;
TCP_Endpoint* resp; TCP_Endpoint* resp;
using analyzer_list = std::list<analyzer::Analyzer*>;
analyzer_list packet_children; analyzer_list packet_children;
unsigned int first_packet_seen: 2; unsigned int first_packet_seen: 2;