From c3f9d09d2296946f05a59cedeeebc078dc7acb41 Mon Sep 17 00:00:00 2001 From: Tomas Babej Date: Fri, 23 Apr 2021 22:39:19 -0400 Subject: [PATCH] performance: Cache used command value The detected command does not change once CLI2::analysis has been performed. Cache the value of the command to avoid the need to re-discover the correct value each time we're interested in it. --- src/CLI2.cpp | 7 +++++++ src/CLI2.h | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) 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