mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Performance
- Added std::string::reserve in high-use locations. - Used Task::get_date over Task::get where possible. - Added missing code (bug) for waking up any completed tasks that are freshly waited. - Greater use of STL methods for bulk copying.
This commit is contained in:
parent
cd552231e9
commit
2668b04901
2 changed files with 29 additions and 15 deletions
|
@ -200,6 +200,7 @@ void File::read (std::string& contents)
|
|||
if (in.good ())
|
||||
{
|
||||
std::string line;
|
||||
line.reserve (1024);
|
||||
while (getline (in, line))
|
||||
contents += line + "\n";
|
||||
|
||||
|
@ -217,6 +218,7 @@ void File::read (std::vector <std::string>& contents)
|
|||
if (in.good ())
|
||||
{
|
||||
std::string line;
|
||||
line.reserve (1024);
|
||||
while (getline (in, line))
|
||||
contents.push_back (line);
|
||||
|
||||
|
@ -357,6 +359,7 @@ std::string File::read (const std::string& name)
|
|||
if (in.good ())
|
||||
{
|
||||
std::string line;
|
||||
line.reserve (1024);
|
||||
while (getline (in, line))
|
||||
contents += line + "\n";
|
||||
|
||||
|
@ -375,6 +378,7 @@ bool File::read (const std::string& name, std::string& contents)
|
|||
if (in.good ())
|
||||
{
|
||||
std::string line;
|
||||
line.reserve (1024);
|
||||
while (getline (in, line))
|
||||
contents += line + "\n";
|
||||
|
||||
|
@ -394,6 +398,7 @@ bool File::read (const std::string& name, std::vector <std::string>& contents)
|
|||
if (in.good ())
|
||||
{
|
||||
std::string line;
|
||||
line.reserve (1024);
|
||||
while (getline (in, line))
|
||||
contents.push_back (line);
|
||||
|
||||
|
|
39
src/TDB2.cpp
39
src/TDB2.cpp
|
@ -1470,8 +1470,8 @@ void TDB2::revert ()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Scans the pending tasks for any that are completed or deleted, and if so,
|
||||
// moves them to the completed.data file. Returns a count of tasks moved.
|
||||
// Now reverts expired waiting tasks to pending.
|
||||
// Now cleans up dangling dependencies.
|
||||
// Reverts expired waiting tasks to pending.
|
||||
// Cleans up dangling dependencies.
|
||||
//
|
||||
// Possible scenarios:
|
||||
// - task in pending that needs to be in completed
|
||||
|
@ -1508,13 +1508,14 @@ int TDB2::gc ()
|
|||
++task)
|
||||
{
|
||||
status = task->get ("status");
|
||||
if (status == "pending" || status == "recurring")
|
||||
if (status == "pending" ||
|
||||
status == "recurring")
|
||||
{
|
||||
pending_tasks_after.push_back (*task);
|
||||
}
|
||||
else if (status == "waiting")
|
||||
{
|
||||
Date wait (task->get ("wait"));
|
||||
Date wait (task->get_date ("wait"));
|
||||
if (wait < now)
|
||||
{
|
||||
task->set ("status", "pending");
|
||||
|
@ -1540,12 +1541,26 @@ int TDB2::gc ()
|
|||
{
|
||||
status = task->get ("status");
|
||||
if (status == "pending" ||
|
||||
status == "waiting")
|
||||
status == "recurring")
|
||||
{
|
||||
pending_tasks_after.push_back (*task);
|
||||
pending_changes = true;
|
||||
completed_changes = true;
|
||||
}
|
||||
else if (status == "waiting")
|
||||
{
|
||||
Date wait (task->get_date ("wait"));
|
||||
if (wait < now)
|
||||
{
|
||||
task->set ("status", "pending");
|
||||
task->remove ("wait");
|
||||
pending_tasks_after.push_back (*task);
|
||||
pending_changes = true;
|
||||
completed_changes = true;
|
||||
}
|
||||
|
||||
pending_tasks_after.push_back (*task);
|
||||
}
|
||||
else
|
||||
{
|
||||
completed_tasks_after.push_back (*task);
|
||||
|
@ -1555,17 +1570,16 @@ int TDB2::gc ()
|
|||
// Only recreate the pending.data file if necessary.
|
||||
if (pending_changes)
|
||||
{
|
||||
pending.clear ();
|
||||
pending._tasks = pending_tasks_after;
|
||||
pending._dirty = true;
|
||||
pending._loaded_tasks = true;
|
||||
_id = 1;
|
||||
|
||||
for (task = pending_tasks_after.begin ();
|
||||
task != pending_tasks_after.end ();
|
||||
for (task = pending._tasks.begin ();
|
||||
task != pending._tasks.end ();
|
||||
++task)
|
||||
{
|
||||
task->id = _id++;
|
||||
pending._tasks.push_back (*task);
|
||||
}
|
||||
|
||||
// Note: deliberately no commit.
|
||||
|
@ -1574,15 +1588,10 @@ int TDB2::gc ()
|
|||
// Only recreate the completed.data file if necessary.
|
||||
if (completed_changes)
|
||||
{
|
||||
completed.clear ();
|
||||
completed._tasks = completed_tasks_after;
|
||||
completed._dirty = true;
|
||||
completed._loaded_tasks = true;
|
||||
|
||||
for (task = completed_tasks_after.begin ();
|
||||
task != completed_tasks_after.end ();
|
||||
++task)
|
||||
completed._tasks.push_back (*task);
|
||||
|
||||
// Note: deliberately no commit.
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue