diff --git a/src/CLI2.cpp b/src/CLI2.cpp index cd57e4dbd..4c5743865 100644 --- a/src/CLI2.cpp +++ b/src/CLI2.cpp @@ -523,6 +523,9 @@ void CLI2::analyze () // Determine arg types: FILTER, MODIFICATION, MISCELLANEOUS. categorizeArgs (); parenthesizeOriginalFilter (); + + // Cache frequently looked up items + _command = getCommand (); } //////////////////////////////////////////////////////////////////////////////// @@ -752,6 +755,10 @@ std::string CLI2::getBinary () const //////////////////////////////////////////////////////////////////////////////// std::string CLI2::getCommand (bool canonical) const { + // Shortcut if analysis has been finalized + if (_command != "") + return _command; + for (const auto& a : _args) if (a.hasTag ("CMD")) return a.attribute (canonical ? "canonical" : "raw"); diff --git a/src/CLI2.h b/src/CLI2.h index b785c9f04..3996bef0b 100644 --- a/src/CLI2.h +++ b/src/CLI2.h @@ -116,7 +116,8 @@ public: std::vector > _id_ranges {}; std::vector _uuid_list {}; - bool _context_added {false}; + std::string _command {""}; + bool _context_added {false}; }; #endif