From 28e997691ff72033c4e1ff94cc90eefc38252d24 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 8 Mar 2009 22:56:47 -0400 Subject: [PATCH] Unit Tests - repair - Added auto right trim to all table rows, which is a much more efficient way of doing what Table::optimize was doing. - Table::optimize is now a nop. --- src/Table.cpp | 48 ++++++++++------------------------------- src/Table.h | 2 +- src/report.cpp | 8 ++----- src/tests/benchmark.txt | 8 +++---- src/tests/bug.sort.t | 1 - 5 files changed, 18 insertions(+), 49 deletions(-) diff --git a/src/Table.cpp b/src/Table.cpp index cce934cfe..fc0ff1296 100644 --- a/src/Table.cpp +++ b/src/Table.cpp @@ -736,19 +736,14 @@ int Table::columnCount () //////////////////////////////////////////////////////////////////////////////// // Removes extraneous output characters, such as: -// - spaces followed by a newline is collapsed to just a newline, if there is -// no Bg color. // - removal of redundant color codes: // ^[[31mName^[[0m ^[[31mValue^[[0m -> ^[[31mName Value^[[0m // // This method is a work in progress. void Table::optimize (std::string& output) const { -/* - int start = output.length (); -*/ +// int start = output.length (); - // \s\n -> \n /* Well, how about that! @@ -770,7 +765,7 @@ void Table::optimize (std::string& output) const This performance is terrible. To identify the worst offender, Various Timer objects were added in Table::render, assuming that table sorting is the major bottleneck. But no, it is Table::optimize that is the problem. After - commenting out the code below, the results are now: + commenting out this method, the results are now: 1000 tasks added in 3 seconds 600 tasks altered in 29 seconds @@ -784,38 +779,11 @@ void Table::optimize (std::string& output) const 'task history' in 0 seconds 'task ghistory' in 0 seconds - Much better. Table::optimize is currently disabled. + Much better. */ - size_t i = 0; - while ((i = output.find (" \n")) != std::string::npos) - { - output = output.substr (0, i) + - output.substr (i + 8, std::string::npos); - } - - while ((i = output.find (" \n")) != std::string::npos) - { - output = output.substr (0, i) + - output.substr (i + 4, std::string::npos); - } - - while ((i = output.find (" \n")) != std::string::npos) - { - output = output.substr (0, i) + - output.substr (i + 2, std::string::npos); - } - - while ((i = output.find (" \n")) != std::string::npos) - { - output = output.substr (0, i) + - output.substr (i + 1, std::string::npos); - } - -/* - std::cout << int ((100 * (start - output.length ()) / start)) - << "%" << std::endl; -*/ +// std::cout << int ((100 * (start - output.length ()) / start)) +// << "%" << std::endl; } //////////////////////////////////////////////////////////////////////////////// @@ -1077,11 +1045,17 @@ const std::string Table::render () else output += blanks[col]; + // Trim right. + output.erase (output.find_last_not_of (" ") + 1); output += "\n"; } } else + { + // Trim right. + output.erase (output.find_last_not_of (" ") + 1); output += "\n"; + } } return output; diff --git a/src/Table.h b/src/Table.h index 765c1116a..4048dae70 100644 --- a/src/Table.h +++ b/src/Table.h @@ -85,7 +85,6 @@ public: int rowCount (); int columnCount (); const std::string render (); - void optimize (std::string&) const; private: std::string getCell (const int, const int); @@ -104,6 +103,7 @@ private: void formatCell (const int, const int, const int, const int, std::vector &, std::string&); void sort (std::vector &); void clean (std::string&); + void optimize (std::string&) const; private: std::vector mColumns; diff --git a/src/report.cpp b/src/report.cpp index f6aa675ca..afa460821 100644 --- a/src/report.cpp +++ b/src/report.cpp @@ -1205,11 +1205,7 @@ std::string handleReportGHistory (TDB& tdb, T& task, Config& conf) else out << "No tasks." << std::endl; - // Eliminate redundant color codes. - std::string optimized = out.str (); - table.optimize (optimized); - - return optimized; + return out.str (); } //////////////////////////////////////////////////////////////////////////////// @@ -2266,7 +2262,7 @@ std::string handleCustomReport ( // Load all pending tasks. std::vector tasks; - tdb.pendingT (tasks); + tdb.allPendingT (tasks); handleRecurrence (tdb, tasks); // Apply filters. diff --git a/src/tests/benchmark.txt b/src/tests/benchmark.txt index 78cfba505..c64d3369e 100644 --- a/src/tests/benchmark.txt +++ b/src/tests/benchmark.txt @@ -29,11 +29,11 @@ New benchmark: 1..4 ok 1 - Created bench.rc - # start=1236558734 + # start=1236565862 # 1000 tasks added in 3 seconds - # 600 tasks altered in 29 seconds - # stop=1236558924 - # total=190 + # 600 tasks altered in 28 seconds + # stop=1236566048 + # total=186 ok 2 - Removed pending.data ok 3 - Removed completed.data ok 4 - Removed bench.rc diff --git a/src/tests/bug.sort.t b/src/tests/bug.sort.t index 0d0d49eac..c1e4588f5 100755 --- a/src/tests/bug.sort.t +++ b/src/tests/bug.sort.t @@ -44,7 +44,6 @@ my $setup = "../task rc:bug_sort.rc add one;" qx{$setup}; my $output = qx{../task rc:bug_sort.rc list}; -#diag ($output); like ($output, qr/three.*(?:one.*two|two.*one)/msi, 'list did not hang'); qx{../task rc:bug_sort.rc 1 priority:H};