- Implemented Command::filter_shortcut to detect when a filter begins
  with "status:pending" and skip the loading/parsing of completed.data.
- Removed obsolete att.t.cpp tests.
- Removed diagnostics from TDB2::TDB2 that were causing a segfault.
  I suppose there is no std::cout available during global ctors?
This commit is contained in:
Paul Beckingham 2011-07-14 00:46:01 -04:00
parent 424dc50a36
commit 3a5370ddf1
5 changed files with 44 additions and 10 deletions

View file

@ -297,7 +297,6 @@ void Command::filter (std::vector <Task>& output)
if (f.size ())
{
const std::vector <Task>& pending = context.tdb2.pending.get_tasks ();
const std::vector <Task>& completed = context.tdb2.completed.get_tasks (); // TODO Optional
Expression e (f);
@ -307,9 +306,15 @@ void Command::filter (std::vector <Task>& output)
if (e.eval (*task))
output.push_back (*task);
for (task = completed.begin (); task != completed.end (); ++task)
if (e.eval (*task))
output.push_back (*task);
if (! filter_shortcut (f))
{
const std::vector <Task>& completed = context.tdb2.completed.get_tasks (); // TODO Optional
for (task = completed.begin (); task != completed.end (); ++task)
if (e.eval (*task))
output.push_back (*task);
}
else
context.debug ("Command::filter skipping completed.data");
}
else
{
@ -325,6 +330,31 @@ void Command::filter (std::vector <Task>& output)
}
}
////////////////////////////////////////////////////////////////////////////////
// If the filter contains the restriction "status:pending", as the first filter
// term, then completed.data does not need to be loaded.
bool Command::filter_shortcut (const Arguments& filter)
{
/**/
if (filter.size () >= 3)
{
std::cout << "# filter[0] " << filter[0]._first << "\n"
<< "# filter[1] " << filter[1]._first << "\n"
<< "# filter[2] " << filter[2]._first << "\n";
}
/**/
// Postfix: <status> <"pending"> <=>
// 0 1 2
if (filter.size () >= 3 &&
filter[0]._first == "status" &&
filter[1]._first.find ("pending") != std::string::npos &&
filter[2]._first == "=")
return true;
return false;
}
////////////////////////////////////////////////////////////////////////////////
// Apply the modifications in arguments to the task.
void Command::modify_task_description_replace (Task& task, Arguments& arguments)

View file

@ -55,6 +55,7 @@ public:
protected:
void filter (std::vector <Task>&, std::vector <Task>&);
void filter (std::vector <Task>&);
bool filter_shortcut (const Arguments&);
void modify_task_description_replace (Task&, Arguments&);
void modify_task_description_prepend (Task&, Arguments&);