mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Code Cleanup
- Removed obsolete code from Table object.
This commit is contained in:
parent
6ea6c79375
commit
14508742f1
2 changed files with 2 additions and 127 deletions
123
src/Table.cpp
123
src/Table.cpp
|
@ -72,14 +72,6 @@ Table::~Table ()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/*
|
|
||||||
void Table::setTableColor (const Color& c)
|
|
||||||
{
|
|
||||||
mColor["table"] = c;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void Table::setTableAlternateColor (const Color& c)
|
void Table::setTableAlternateColor (const Color& c)
|
||||||
{
|
{
|
||||||
|
@ -123,17 +115,6 @@ int Table::addColumn (const std::string& col)
|
||||||
return mColumns.size () - 1;
|
return mColumns.size () - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// TODO Obsolete - this call is not used. Consider removal.
|
|
||||||
/*
|
|
||||||
void Table::setColumnColor (int column, const Color& c)
|
|
||||||
{
|
|
||||||
char id[12];
|
|
||||||
sprintf (id, "col:%d", column);
|
|
||||||
mColor[id] = c;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void Table::setColumnUnderline (int column)
|
void Table::setColumnUnderline (int column)
|
||||||
{
|
{
|
||||||
|
@ -358,30 +339,6 @@ Color Table::getColor (const int index, const int row, const int col)
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// TODO Obsolete - this is not used. Consider removal.
|
|
||||||
Color Table::getHeaderColor (int col)
|
|
||||||
{
|
|
||||||
// Color defaults to trivial.
|
|
||||||
Color c;
|
|
||||||
|
|
||||||
/*
|
|
||||||
std::map <std::string, Color>::iterator i;
|
|
||||||
char id[24];
|
|
||||||
|
|
||||||
// Blend with a table color, if specified.
|
|
||||||
if ((i = mColor.find ("table")) != mColor.end ())
|
|
||||||
c.blend (i->second);
|
|
||||||
|
|
||||||
// Blend with a column color, if specified.
|
|
||||||
sprintf (id, "col:%d", col);
|
|
||||||
if ((i = mColor.find (id)) != mColor.end ())
|
|
||||||
c.blend (i->second);
|
|
||||||
*/
|
|
||||||
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
Color Table::getHeaderUnderline (int col)
|
Color Table::getHeaderUnderline (int col)
|
||||||
{
|
{
|
||||||
|
@ -526,9 +483,8 @@ const std::string Table::formatHeader (
|
||||||
{
|
{
|
||||||
assert (width > 0);
|
assert (width > 0);
|
||||||
|
|
||||||
Color c = getHeaderColor (col);
|
|
||||||
std::string data = mColumns[col];
|
std::string data = mColumns[col];
|
||||||
c.blend (getHeaderUnderline (col));
|
Color c = getHeaderUnderline (col);
|
||||||
|
|
||||||
std::string pad = "";
|
std::string pad = "";
|
||||||
std::string intraPad = "";
|
std::string intraPad = "";
|
||||||
|
@ -575,8 +531,7 @@ const std::string Table::formatHeaderDashedUnderline (
|
||||||
{
|
{
|
||||||
assert (width > 0);
|
assert (width > 0);
|
||||||
|
|
||||||
Color c = getHeaderColor (col);
|
Color c = getHeaderUnderline (col);
|
||||||
c.blend (getHeaderUnderline (col));
|
|
||||||
|
|
||||||
std::string data = "";
|
std::string data = "";
|
||||||
for (int i = 0; i < width; ++i)
|
for (int i = 0; i < width; ++i)
|
||||||
|
@ -695,79 +650,6 @@ int Table::columnCount ()
|
||||||
return mColumns.size ();
|
return mColumns.size ();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Removes extraneous output characters, such as:
|
|
||||||
// - 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 ();
|
|
||||||
|
|
||||||
/*
|
|
||||||
Well, how about that!
|
|
||||||
|
|
||||||
The benchmark.t unit test adds a 1000 tasks, fiddles with some of them, then
|
|
||||||
runs a series of reports. The results are timed, and look like this:
|
|
||||||
|
|
||||||
1000 tasks added in 3 seconds
|
|
||||||
600 tasks altered in 32 seconds
|
|
||||||
'task ls' in 26 seconds
|
|
||||||
'task list' in 17 seconds
|
|
||||||
'task list pri:H' in 19 seconds
|
|
||||||
'task list +tag' in 0 seconds
|
|
||||||
'task list project_A' in 0 seconds
|
|
||||||
'task long' in 29 seconds
|
|
||||||
'task completed' in 2 seconds
|
|
||||||
'task history' in 0 seconds
|
|
||||||
'task ghistory' in 0 seconds
|
|
||||||
|
|
||||||
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 this method, the results are now:
|
|
||||||
|
|
||||||
1000 tasks added in 3 seconds
|
|
||||||
600 tasks altered in 29 seconds
|
|
||||||
'task ls' in 0 seconds
|
|
||||||
'task list' in 0 seconds
|
|
||||||
'task list pri:H' in 1 seconds
|
|
||||||
'task list +tag' in 0 seconds
|
|
||||||
'task list project_A' in 0 seconds
|
|
||||||
'task long' in 0 seconds
|
|
||||||
'task completed' in 0 seconds
|
|
||||||
'task history' in 0 seconds
|
|
||||||
'task ghistory' in 0 seconds
|
|
||||||
|
|
||||||
Much better.
|
|
||||||
*/
|
|
||||||
|
|
||||||
char patterns[5][16] =
|
|
||||||
{
|
|
||||||
" \n",
|
|
||||||
" \n",
|
|
||||||
" \n",
|
|
||||||
" \n",
|
|
||||||
};
|
|
||||||
|
|
||||||
std::string::size_type trailing;
|
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++)
|
|
||||||
{
|
|
||||||
do
|
|
||||||
{
|
|
||||||
trailing = output.find (patterns[i]);
|
|
||||||
if (trailing != std::string::npos)
|
|
||||||
output.replace (trailing, strlen (patterns[i]), "\n");
|
|
||||||
}
|
|
||||||
while (trailing != std::string::npos);
|
|
||||||
}
|
|
||||||
|
|
||||||
// std::cout << int ((100 * (start - output.length ()) / start))
|
|
||||||
// << "%" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Combsort11, with O(n log n) average, O(n log n) worst case performance.
|
// Combsort11, with O(n log n) average, O(n log n) worst case performance.
|
||||||
//
|
//
|
||||||
|
@ -1133,7 +1015,6 @@ const std::string Table::render (int maxrows /* = 0 */, int maxlines /* = 0 */)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
optimize (output);
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,8 +57,6 @@ public:
|
||||||
Table (const Table&);
|
Table (const Table&);
|
||||||
Table& operator= (const Table&);
|
Table& operator= (const Table&);
|
||||||
|
|
||||||
// TODO Obsolete - this is not used. Consider removal.
|
|
||||||
// void setTableColor (const Color&);
|
|
||||||
void setTableAlternateColor (const Color&);
|
void setTableAlternateColor (const Color&);
|
||||||
void setTablePadding (int);
|
void setTablePadding (int);
|
||||||
void setTableIntraPadding (int);
|
void setTableIntraPadding (int);
|
||||||
|
@ -66,8 +64,6 @@ public:
|
||||||
void setTableDashedUnderline ();
|
void setTableDashedUnderline ();
|
||||||
|
|
||||||
int addColumn (const std::string&);
|
int addColumn (const std::string&);
|
||||||
// TODO Obsolete - this is not used. Consider removal.
|
|
||||||
// void setColumnColor (int, const Color&);
|
|
||||||
void setColumnUnderline (int);
|
void setColumnUnderline (int);
|
||||||
void setColumnPadding (int, int);
|
void setColumnPadding (int, int);
|
||||||
void setColumnWidth (int, int);
|
void setColumnWidth (int, int);
|
||||||
|
@ -97,7 +93,6 @@ public:
|
||||||
private:
|
private:
|
||||||
std::string getCell (const int, const int);
|
std::string getCell (const int, const int);
|
||||||
Color getColor (const int, const int, const int);
|
Color getColor (const int, const int, const int);
|
||||||
Color getHeaderColor (const int);
|
|
||||||
Color getHeaderUnderline (const int);
|
Color getHeaderUnderline (const int);
|
||||||
int getPadding (const int);
|
int getPadding (const int);
|
||||||
int getIntraPadding ();
|
int getIntraPadding ();
|
||||||
|
@ -109,7 +104,6 @@ private:
|
||||||
void formatCell (const int, const int, const int, const int, const int, std::vector <std::string>&, std::string&);
|
void formatCell (const int, const int, const int, const int, const int, std::vector <std::string>&, std::string&);
|
||||||
void sort (std::vector <int>&);
|
void sort (std::vector <int>&);
|
||||||
void clean (std::string&);
|
void clean (std::string&);
|
||||||
void optimize (std::string&) const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector <std::string> mColumns;
|
std::vector <std::string> mColumns;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue