diff --git a/ChangeLog b/ChangeLog index 8c62c2a1e..fce4190b9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -48,6 +48,8 @@ Features + Rewritten task-sync(5) man page, listing sync options and setup guidelines.. + Now properly uses the libc version of uuid_create and uuid_to_string for FreeBSD (thanks to Pietro Cerutti). + + Performance improvements: + + Optimizes indexing into pending.data for direct task access. Bugs + #1195 Random seed not random enough - removed all random number code (thanks diff --git a/src/TDB2.cpp b/src/TDB2.cpp index 91f5cbea8..8f328e6a0 100644 --- a/src/TDB2.cpp +++ b/src/TDB2.cpp @@ -112,12 +112,15 @@ bool TF2::get (int id, Task& task) if (! _loaded_tasks) load_tasks (); - std::vector ::iterator i; - for (i = _tasks.begin (); i != _tasks.end (); ++i) + // This is an optimization. Since the 'id' is based on the line number of + // pending.data file, the task in question cannot appear earlier than line + // (id - 1) in the file. It can, however, appear significantly later because + // it is not known how recent a GC operation was run. + for (int i = id - 1; i < _tasks.size (); ++i) { - if (i->id == id) + if (_tasks[i].id == id) { - task = *i; + task = _tasks[i]; return true; } }