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:
Paul Beckingham
2012-04-27 02:46:01 -04:00
parent cd552231e9
commit 2668b04901
2 changed files with 29 additions and 15 deletions

View File

@@ -200,6 +200,7 @@ void File::read (std::string& contents)
if (in.good ()) if (in.good ())
{ {
std::string line; std::string line;
line.reserve (1024);
while (getline (in, line)) while (getline (in, line))
contents += line + "\n"; contents += line + "\n";
@@ -217,6 +218,7 @@ void File::read (std::vector <std::string>& contents)
if (in.good ()) if (in.good ())
{ {
std::string line; std::string line;
line.reserve (1024);
while (getline (in, line)) while (getline (in, line))
contents.push_back (line); contents.push_back (line);
@@ -357,6 +359,7 @@ std::string File::read (const std::string& name)
if (in.good ()) if (in.good ())
{ {
std::string line; std::string line;
line.reserve (1024);
while (getline (in, line)) while (getline (in, line))
contents += line + "\n"; contents += line + "\n";
@@ -375,6 +378,7 @@ bool File::read (const std::string& name, std::string& contents)
if (in.good ()) if (in.good ())
{ {
std::string line; std::string line;
line.reserve (1024);
while (getline (in, line)) while (getline (in, line))
contents += line + "\n"; contents += line + "\n";
@@ -394,6 +398,7 @@ bool File::read (const std::string& name, std::vector <std::string>& contents)
if (in.good ()) if (in.good ())
{ {
std::string line; std::string line;
line.reserve (1024);
while (getline (in, line)) while (getline (in, line))
contents.push_back (line); contents.push_back (line);

View File

@@ -1470,8 +1470,8 @@ void TDB2::revert ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Scans the pending tasks for any that are completed or deleted, and if so, // 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. // moves them to the completed.data file. Returns a count of tasks moved.
// Now reverts expired waiting tasks to pending. // Reverts expired waiting tasks to pending.
// Now cleans up dangling dependencies. // Cleans up dangling dependencies.
// //
// Possible scenarios: // Possible scenarios:
// - task in pending that needs to be in completed // - task in pending that needs to be in completed
@@ -1508,13 +1508,14 @@ int TDB2::gc ()
++task) ++task)
{ {
status = task->get ("status"); status = task->get ("status");
if (status == "pending" || status == "recurring") if (status == "pending" ||
status == "recurring")
{ {
pending_tasks_after.push_back (*task); pending_tasks_after.push_back (*task);
} }
else if (status == "waiting") else if (status == "waiting")
{ {
Date wait (task->get ("wait")); Date wait (task->get_date ("wait"));
if (wait < now) if (wait < now)
{ {
task->set ("status", "pending"); task->set ("status", "pending");
@@ -1540,12 +1541,26 @@ int TDB2::gc ()
{ {
status = task->get ("status"); status = task->get ("status");
if (status == "pending" || if (status == "pending" ||
status == "waiting") status == "recurring")
{ {
pending_tasks_after.push_back (*task); pending_tasks_after.push_back (*task);
pending_changes = true; pending_changes = true;
completed_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 else
{ {
completed_tasks_after.push_back (*task); completed_tasks_after.push_back (*task);
@@ -1555,17 +1570,16 @@ int TDB2::gc ()
// Only recreate the pending.data file if necessary. // Only recreate the pending.data file if necessary.
if (pending_changes) if (pending_changes)
{ {
pending.clear (); pending._tasks = pending_tasks_after;
pending._dirty = true; pending._dirty = true;
pending._loaded_tasks = true; pending._loaded_tasks = true;
_id = 1; _id = 1;
for (task = pending_tasks_after.begin (); for (task = pending._tasks.begin ();
task != pending_tasks_after.end (); task != pending._tasks.end ();
++task) ++task)
{ {
task->id = _id++; task->id = _id++;
pending._tasks.push_back (*task);
} }
// Note: deliberately no commit. // Note: deliberately no commit.
@@ -1574,15 +1588,10 @@ int TDB2::gc ()
// Only recreate the completed.data file if necessary. // Only recreate the completed.data file if necessary.
if (completed_changes) if (completed_changes)
{ {
completed.clear (); completed._tasks = completed_tasks_after;
completed._dirty = true; completed._dirty = true;
completed._loaded_tasks = 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. // Note: deliberately no commit.
} }