Optimization

- TDB::load can entirely skip the loading of completed.data if the
  specified filter is just so.
- Added FEATURE_TDB_OPT definition to allow disabling of this.
This commit is contained in:
Paul Beckingham 2009-06-16 18:33:49 -04:00
parent 7a77cd6d4a
commit e7a0a20d55
2 changed files with 31 additions and 1 deletions

View file

@ -151,8 +151,34 @@ void TDB::unlock ()
// multiple files.
int TDB::load (std::vector <Task>& tasks, Filter& filter)
{
loadPending (tasks, filter);
#ifdef FEATURE_TDB_OPT
// Special optimization: if the filter contains Att ('status', '', 'pending'),
// and no other 'status' filters, then loadCompleted can be skipped.
int numberStatusClauses = 0;
int numberSimpleStatusClauses = 0;
foreach (att, filter)
{
if (att->name () == "status")
{
++numberStatusClauses;
if (att->mod () == "" && att->value () == "pending")
++numberSimpleStatusClauses;
}
}
#endif
loadPending (tasks, filter);
#ifdef FEATURE_TDB_OPT
if (numberStatusClauses == 0 ||
numberStatusClauses != numberSimpleStatusClauses)
loadCompleted (tasks, filter);
else
std::cout << "# TDB::load optimization short circuit" << std::endl;
#else
loadCompleted (tasks, filter);
#endif
return tasks.size ();
}

View file

@ -25,6 +25,10 @@
//
////////////////////////////////////////////////////////////////////////////////
// TDB Optimization attempts to reduce the amount of I/O.
#define FEATURE_TDB_OPT 1
#include <string>
#include <vector>
#include <map>