From cd552231e974a8b5fffabdcb0e2ae7e79b993baa Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Fri, 27 Apr 2012 01:49:26 -0400 Subject: [PATCH] Performance - Eliminated the 'contents' layer, which was never used to the degree anticipated. This reduces memory footprint significantly. --- src/TDB2.cpp | 36 ++++-------------------------------- src/TDB2.h | 4 ---- 2 files changed, 4 insertions(+), 36 deletions(-) diff --git a/src/TDB2.cpp b/src/TDB2.cpp index 58811ee41..00c3c0d7b 100644 --- a/src/TDB2.cpp +++ b/src/TDB2.cpp @@ -66,9 +66,7 @@ TF2::TF2 () , _dirty (false) , _loaded_tasks (false) , _loaded_lines (false) -, _loaded_contents (false) , _has_ids (false) -, _contents ("") { } @@ -106,15 +104,6 @@ const std::vector & TF2::get_lines () return _lines; } -//////////////////////////////////////////////////////////////////////////////// -const std::string& TF2::get_contents () -{ - if (! _loaded_contents) - load_contents (); - - return _contents; -} - //////////////////////////////////////////////////////////////////////////////// void TF2::add_task (const Task& task) { @@ -297,25 +286,13 @@ void TF2::load_tasks () //////////////////////////////////////////////////////////////////////////////// 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 (context.config.getBoolean ("locking")) _file.lock (); - _file.read (_contents); - _loaded_contents = true; + _file.read (_lines); + _loaded_lines = true; } } @@ -373,9 +350,6 @@ void TF2::clear () _dirty = false; _loaded_tasks = false; _loaded_lines = false; - _loaded_contents = false; - - _contents = ""; // Note that the actual file name, and _has_ids are deliberately not cleared. //_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 lines = green.colorize (rightJustifyZero ((int) _lines.size (), 4)); 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. - 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 (), mode.c_str (), hygiene.c_str (), @@ -429,8 +402,7 @@ const std::string TF2::dump () tasks_added.c_str (), tasks_modified.c_str (), lines.c_str (), - lines_added.c_str (), - contents.c_str ()); + lines_added.c_str ()); return std::string (buffer); } diff --git a/src/TDB2.h b/src/TDB2.h index 56d2685cc..cf965eae9 100644 --- a/src/TDB2.h +++ b/src/TDB2.h @@ -48,7 +48,6 @@ public: const std::vector & get_tasks (); const std::vector & get_lines (); - const std::string& get_contents (); void add_task (const Task&); bool modify_task (const Task&); @@ -58,7 +57,6 @@ public: void load_tasks (); void load_lines (); - void load_contents (); // ID <--> UUID mapping. std::string uuid (int); @@ -73,14 +71,12 @@ public: bool _dirty; bool _loaded_tasks; bool _loaded_lines; - bool _loaded_contents; bool _has_ids; std::vector _tasks; std::vector _added_tasks; std::vector _modified_tasks; std::vector _lines; std::vector _added_lines; - std::string _contents; File _file; private: