mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-19 19:03:07 +02:00
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.
This commit is contained in:
parent
a19773873a
commit
c3f9d09d22
2 changed files with 9 additions and 1 deletions
|
|
@ -523,6 +523,9 @@ void CLI2::analyze ()
|
||||||
// Determine arg types: FILTER, MODIFICATION, MISCELLANEOUS.
|
// Determine arg types: FILTER, MODIFICATION, MISCELLANEOUS.
|
||||||
categorizeArgs ();
|
categorizeArgs ();
|
||||||
parenthesizeOriginalFilter ();
|
parenthesizeOriginalFilter ();
|
||||||
|
|
||||||
|
// Cache frequently looked up items
|
||||||
|
_command = getCommand ();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
@ -752,6 +755,10 @@ std::string CLI2::getBinary () const
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
std::string CLI2::getCommand (bool canonical) const
|
std::string CLI2::getCommand (bool canonical) const
|
||||||
{
|
{
|
||||||
|
// Shortcut if analysis has been finalized
|
||||||
|
if (_command != "")
|
||||||
|
return _command;
|
||||||
|
|
||||||
for (const auto& a : _args)
|
for (const auto& a : _args)
|
||||||
if (a.hasTag ("CMD"))
|
if (a.hasTag ("CMD"))
|
||||||
return a.attribute (canonical ? "canonical" : "raw");
|
return a.attribute (canonical ? "canonical" : "raw");
|
||||||
|
|
|
||||||
|
|
@ -116,6 +116,7 @@ public:
|
||||||
|
|
||||||
std::vector <std::pair <std::string, std::string>> _id_ranges {};
|
std::vector <std::pair <std::string, std::string>> _id_ranges {};
|
||||||
std::vector <std::string> _uuid_list {};
|
std::vector <std::string> _uuid_list {};
|
||||||
|
std::string _command {""};
|
||||||
bool _context_added {false};
|
bool _context_added {false};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue