Performance

- Eliminated the 'contents' layer, which was never used to the degree
  anticipated.  This reduces memory footprint significantly.
This commit is contained in:
Paul Beckingham 2012-04-27 01:49:26 -04:00
parent f47648c71f
commit cd552231e9
2 changed files with 4 additions and 36 deletions

View file

@ -66,9 +66,7 @@ TF2::TF2 ()
, _dirty (false) , _dirty (false)
, _loaded_tasks (false) , _loaded_tasks (false)
, _loaded_lines (false) , _loaded_lines (false)
, _loaded_contents (false)
, _has_ids (false) , _has_ids (false)
, _contents ("")
{ {
} }
@ -106,15 +104,6 @@ const std::vector <std::string>& TF2::get_lines ()
return _lines; return _lines;
} }
////////////////////////////////////////////////////////////////////////////////
const std::string& TF2::get_contents ()
{
if (! _loaded_contents)
load_contents ();
return _contents;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void TF2::add_task (const Task& task) void TF2::add_task (const Task& task)
{ {
@ -297,25 +286,13 @@ void TF2::load_tasks ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void TF2::load_lines () void TF2::load_lines ()
{ {
if (! _loaded_contents)
load_contents ();
split_minimal (_lines, _contents, '\n');
_loaded_lines = true;
}
////////////////////////////////////////////////////////////////////////////////
void TF2::load_contents ()
{
_contents = "";
if (_file.open ()) if (_file.open ())
{ {
if (context.config.getBoolean ("locking")) if (context.config.getBoolean ("locking"))
_file.lock (); _file.lock ();
_file.read (_contents); _file.read (_lines);
_loaded_contents = true; _loaded_lines = true;
} }
} }
@ -373,9 +350,6 @@ void TF2::clear ()
_dirty = false; _dirty = false;
_loaded_tasks = false; _loaded_tasks = false;
_loaded_lines = false; _loaded_lines = false;
_loaded_contents = false;
_contents = "";
// Note that the actual file name, and _has_ids are deliberately not cleared. // Note that the actual file name, and _has_ids are deliberately not cleared.
//_file._data = ""; //_file._data = "";
@ -418,10 +392,9 @@ const std::string TF2::dump ()
std::string tasks_modified = yellow.colorize (rightJustifyZero ((int) _modified_tasks.size (), 3)); std::string tasks_modified = yellow.colorize (rightJustifyZero ((int) _modified_tasks.size (), 3));
std::string lines = green.colorize (rightJustifyZero ((int) _lines.size (), 4)); std::string lines = green.colorize (rightJustifyZero ((int) _lines.size (), 4));
std::string lines_added = red.colorize (rightJustifyZero ((int) _added_lines.size (), 3)); std::string lines_added = red.colorize (rightJustifyZero ((int) _added_lines.size (), 3));
std::string contents = green.colorize (rightJustifyZero ((int) _contents.size (), 6));
char buffer[256]; // Composed string is actually 246 bytes. Yikes. char buffer[256]; // Composed string is actually 246 bytes. Yikes.
snprintf (buffer, 256, "%14s %s %s T%s+%s~%s L%s+%s C%s", snprintf (buffer, 256, "%14s %s %s T%s+%s~%s L%s+%s",
label.c_str (), label.c_str (),
mode.c_str (), mode.c_str (),
hygiene.c_str (), hygiene.c_str (),
@ -429,8 +402,7 @@ const std::string TF2::dump ()
tasks_added.c_str (), tasks_added.c_str (),
tasks_modified.c_str (), tasks_modified.c_str (),
lines.c_str (), lines.c_str (),
lines_added.c_str (), lines_added.c_str ());
contents.c_str ());
return std::string (buffer); return std::string (buffer);
} }

View file

@ -48,7 +48,6 @@ public:
const std::vector <Task>& get_tasks (); const std::vector <Task>& get_tasks ();
const std::vector <std::string>& get_lines (); const std::vector <std::string>& get_lines ();
const std::string& get_contents ();
void add_task (const Task&); void add_task (const Task&);
bool modify_task (const Task&); bool modify_task (const Task&);
@ -58,7 +57,6 @@ public:
void load_tasks (); void load_tasks ();
void load_lines (); void load_lines ();
void load_contents ();
// ID <--> UUID mapping. // ID <--> UUID mapping.
std::string uuid (int); std::string uuid (int);
@ -73,14 +71,12 @@ public:
bool _dirty; bool _dirty;
bool _loaded_tasks; bool _loaded_tasks;
bool _loaded_lines; bool _loaded_lines;
bool _loaded_contents;
bool _has_ids; bool _has_ids;
std::vector <Task> _tasks; std::vector <Task> _tasks;
std::vector <Task> _added_tasks; std::vector <Task> _added_tasks;
std::vector <Task> _modified_tasks; std::vector <Task> _modified_tasks;
std::vector <std::string> _lines; std::vector <std::string> _lines;
std::vector <std::string> _added_lines; std::vector <std::string> _added_lines;
std::string _contents;
File _file; File _file;
private: private: