From 14508742f10ae510c5c7e1ccb104a4220cea8f9f Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Mon, 28 Jun 2010 17:46:27 -0400 Subject: [PATCH] Code Cleanup - Removed obsolete code from Table object. --- src/Table.cpp | 123 +------------------------------------------------- src/Table.h | 6 --- 2 files changed, 2 insertions(+), 127 deletions(-) diff --git a/src/Table.cpp b/src/Table.cpp index a9771f196..6bc8c931f 100644 --- a/src/Table.cpp +++ b/src/Table.cpp @@ -72,14 +72,6 @@ Table::~Table () { } -//////////////////////////////////////////////////////////////////////////////// -/* -void Table::setTableColor (const Color& c) -{ - mColor["table"] = c; -} -*/ - //////////////////////////////////////////////////////////////////////////////// void Table::setTableAlternateColor (const Color& c) { @@ -123,17 +115,6 @@ int Table::addColumn (const std::string& col) 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) { @@ -358,30 +339,6 @@ Color Table::getColor (const int index, const int row, const int col) return c; } -//////////////////////////////////////////////////////////////////////////////// -// TODO Obsolete - this is not used. Consider removal. -Color Table::getHeaderColor (int col) -{ - // Color defaults to trivial. - Color c; - -/* - std::map ::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) { @@ -526,9 +483,8 @@ const std::string Table::formatHeader ( { assert (width > 0); - Color c = getHeaderColor (col); std::string data = mColumns[col]; - c.blend (getHeaderUnderline (col)); + Color c = getHeaderUnderline (col); std::string pad = ""; std::string intraPad = ""; @@ -575,8 +531,7 @@ const std::string Table::formatHeaderDashedUnderline ( { assert (width > 0); - Color c = getHeaderColor (col); - c.blend (getHeaderUnderline (col)); + Color c = getHeaderUnderline (col); std::string data = ""; for (int i = 0; i < width; ++i) @@ -695,79 +650,6 @@ int Table::columnCount () 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. // @@ -1133,7 +1015,6 @@ const std::string Table::render (int maxrows /* = 0 */, int maxlines /* = 0 */) break; } - optimize (output); return output; } diff --git a/src/Table.h b/src/Table.h index e04417496..73ffd8c34 100644 --- a/src/Table.h +++ b/src/Table.h @@ -57,8 +57,6 @@ public: Table (const Table&); Table& operator= (const Table&); -// TODO Obsolete - this is not used. Consider removal. -// void setTableColor (const Color&); void setTableAlternateColor (const Color&); void setTablePadding (int); void setTableIntraPadding (int); @@ -66,8 +64,6 @@ public: void setTableDashedUnderline (); int addColumn (const std::string&); -// TODO Obsolete - this is not used. Consider removal. -// void setColumnColor (int, const Color&); void setColumnUnderline (int); void setColumnPadding (int, int); void setColumnWidth (int, int); @@ -97,7 +93,6 @@ public: private: std::string getCell (const int, const int); Color getColor (const int, const int, const int); - Color getHeaderColor (const int); Color getHeaderUnderline (const int); int getPadding (const int); int getIntraPadding (); @@ -109,7 +104,6 @@ private: void formatCell (const int, 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;