mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-09-10 04:00:37 +02:00
convert manual loops to std::count_if
Simpler and generates less assembly. Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
parent
62399239ca
commit
73575f8d88
3 changed files with 4 additions and 18 deletions
|
@ -57,11 +57,7 @@ int CmdCount::execute (std::string& output)
|
||||||
filter.subset (filtered);
|
filter.subset (filtered);
|
||||||
|
|
||||||
// Find number of matching tasks. Skip recurring parent tasks.
|
// Find number of matching tasks. Skip recurring parent tasks.
|
||||||
int count = 0;
|
int count = std::count_if(filtered.begin(), filtered.end(), [](const auto& task){ return task.getStatus () != Task::recurring; });
|
||||||
for (const auto& task : filtered)
|
|
||||||
if (task.getStatus () != Task::recurring)
|
|
||||||
++count;
|
|
||||||
|
|
||||||
output = format (count) + '\n';
|
output = format (count) + '\n';
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,17 +70,11 @@ int CmdStats::execute (std::string& output)
|
||||||
|
|
||||||
// Count the undo transactions.
|
// Count the undo transactions.
|
||||||
std::vector <std::string> undoTxns = Context::getContext ().tdb2.undo.get_lines ();
|
std::vector <std::string> undoTxns = Context::getContext ().tdb2.undo.get_lines ();
|
||||||
int undoCount = 0;
|
int undoCount = std::count(undoTxns.begin(), undoTxns.end(), "---");
|
||||||
for (auto& tx : undoTxns)
|
|
||||||
if (tx == "---")
|
|
||||||
++undoCount;
|
|
||||||
|
|
||||||
// Count the backlog transactions.
|
// Count the backlog transactions.
|
||||||
std::vector <std::string> backlogTxns = Context::getContext ().tdb2.backlog.get_lines ();
|
std::vector <std::string> backlogTxns = Context::getContext ().tdb2.backlog.get_lines ();
|
||||||
int backlogCount = 0;
|
int backlogCount = std::count_if(backlogTxns.begin(), backlogTxns.end(), [](const auto& tx){ return tx.front() == '{'; });
|
||||||
for (auto& tx : backlogTxns)
|
|
||||||
if (tx[0] == '{')
|
|
||||||
++backlogCount;
|
|
||||||
|
|
||||||
// Get all the tasks.
|
// Get all the tasks.
|
||||||
Filter filter;
|
Filter filter;
|
||||||
|
|
|
@ -406,12 +406,8 @@ void feedback_backlog ()
|
||||||
if (Context::getContext ().config.get ("taskd.server") != "" &&
|
if (Context::getContext ().config.get ("taskd.server") != "" &&
|
||||||
Context::getContext ().verbose ("sync"))
|
Context::getContext ().verbose ("sync"))
|
||||||
{
|
{
|
||||||
int count = 0;
|
|
||||||
std::vector <std::string> lines = Context::getContext ().tdb2.backlog.get_lines ();
|
std::vector <std::string> lines = Context::getContext ().tdb2.backlog.get_lines ();
|
||||||
for (auto& line : lines)
|
int count = std::count_if(lines.begin(), lines.end(), [](const auto& line){ return line.front() == '{'; });
|
||||||
if ((line)[0] == '{')
|
|
||||||
++count;
|
|
||||||
|
|
||||||
if (count)
|
if (count)
|
||||||
Context::getContext ().footnote (format (count > 1 ? "There are {1} local changes. Sync required."
|
Context::getContext ().footnote (format (count > 1 ? "There are {1} local changes. Sync required."
|
||||||
: "There is {1} local change. Sync required.", count));
|
: "There is {1} local change. Sync required.", count));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue