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.
This commit is contained in:
Paul Beckingham 2009-03-08 22:56:47 -04:00
parent 3f418c6fdc
commit 28e997691f
5 changed files with 18 additions and 49 deletions

View file

@ -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;

View file

@ -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>&, std::string&);
void sort (std::vector <int>&);
void clean (std::string&);
void optimize (std::string&) const;
private:
std::vector <std::string> mColumns;

View file

@ -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 <T> tasks;
tdb.pendingT (tasks);
tdb.allPendingT (tasks);
handleRecurrence (tdb, tasks);
// Apply filters.

View file

@ -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

View file

@ -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};