mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
- Integrated Grid object for data storage.
time ./task lo old new real 0.262 0.018 user 0.201 0.013 sys 0.048 0.004 ~1200-1400% faster time ./task completed old new real 3.991 4.014 user 2.821 2.832 sys 1.165 1.169 ~0.3-0.5% slower
This commit is contained in:
parent
3dd45611ff
commit
b63cf606f0
5 changed files with 90 additions and 97 deletions
|
@ -113,6 +113,15 @@ void Grid::add (
|
|||
insertCell (row, col, new Cell (value));
|
||||
}
|
||||
|
||||
void Grid::add (
|
||||
const unsigned int row,
|
||||
const unsigned int col,
|
||||
const char* value)
|
||||
{
|
||||
expandGrid (row, col);
|
||||
insertCell (row, col, new Cell (std::string (value)));
|
||||
}
|
||||
|
||||
void Grid::add (
|
||||
const unsigned int row,
|
||||
const unsigned int col,
|
||||
|
|
|
@ -55,6 +55,7 @@ public:
|
|||
void add (const unsigned int, const unsigned int, const int);
|
||||
void add (const unsigned int, const unsigned int, const float);
|
||||
void add (const unsigned int, const unsigned int, const double);
|
||||
void add (const unsigned int, const unsigned int, const char*);
|
||||
void add (const unsigned int, const unsigned int, const std::string&);
|
||||
|
||||
unsigned int width () const;
|
||||
|
|
141
src/Table.cpp
141
src/Table.cpp
|
@ -170,7 +170,7 @@ int Table::addRow ()
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Table::setRowColor (int row, Text::color fg, Text::color bg)
|
||||
void Table::setRowColor (const int row, const Text::color fg, const Text::color bg)
|
||||
{
|
||||
char id[12];
|
||||
sprintf (id, "row:%d", row);
|
||||
|
@ -179,7 +179,7 @@ void Table::setRowColor (int row, Text::color fg, Text::color bg)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Table::setRowFg (int row, Text::color c)
|
||||
void Table::setRowFg (const int row, const Text::color c)
|
||||
{
|
||||
char id[12];
|
||||
sprintf (id, "row:%d", row);
|
||||
|
@ -187,7 +187,7 @@ void Table::setRowFg (int row, Text::color c)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Table::setRowBg (int row, Text::color c)
|
||||
void Table::setRowBg (const int row, const Text::color c)
|
||||
{
|
||||
char id[12];
|
||||
sprintf (id, "row:%d", row);
|
||||
|
@ -195,11 +195,8 @@ void Table::setRowBg (int row, Text::color c)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Table::addCell (int row, int col, const std::string& data)
|
||||
void Table::addCell (const int row, const int col, const std::string& data)
|
||||
{
|
||||
char id[24];
|
||||
sprintf (id, "cell:%d,%d", row, col);
|
||||
|
||||
int length = 0;
|
||||
|
||||
if (mSuppressWS)
|
||||
|
@ -212,14 +209,14 @@ void Table::addCell (int row, int col, const std::string& data)
|
|||
|
||||
clean (data2);
|
||||
length = data2.length ();
|
||||
mData[id] = data2;
|
||||
mData.add (row, col, data2);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mCommify.find (col) != mCommify.end ())
|
||||
mData[id] = commify (data);
|
||||
mData.add (row, col, commify (data));
|
||||
else
|
||||
mData[id] = data;
|
||||
mData.add (row, col, data);
|
||||
|
||||
length = data.length ();
|
||||
}
|
||||
|
@ -229,76 +226,61 @@ void Table::addCell (int row, int col, const std::string& data)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Table::addCell (int row, int col, char data)
|
||||
void Table::addCell (const int row, const int col, const char data)
|
||||
{
|
||||
char id[24];
|
||||
sprintf (id, "cell:%d,%d", row, col);
|
||||
|
||||
char value[2];
|
||||
sprintf (value, "%c", data);
|
||||
|
||||
mData[id] = value;
|
||||
mData.add (row, col, data);
|
||||
|
||||
// Automatically maintain max width.
|
||||
mMaxDataWidth[col] = max (mMaxDataWidth[col], (signed) ::strlen (value));
|
||||
mMaxDataWidth[col] = max (mMaxDataWidth[col], 1);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Table::addCell (int row, int col, int data)
|
||||
void Table::addCell (const int row, const int col, const int data)
|
||||
{
|
||||
char id[24];
|
||||
sprintf (id, "cell:%d,%d", row, col);
|
||||
|
||||
char value[12];
|
||||
sprintf (value, "%d", data);
|
||||
|
||||
if (mCommify.find (col) != mCommify.end ())
|
||||
mData[id] = commify (value);
|
||||
mData.add (row, col, commify (value));
|
||||
else
|
||||
mData[id] = value;
|
||||
mData.add (row, col, value);
|
||||
|
||||
// Automatically maintain max width.
|
||||
mMaxDataWidth[col] = max (mMaxDataWidth[col], (signed) ::strlen (value));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Table::addCell (int row, int col, float data)
|
||||
void Table::addCell (const int row, const int col, const float data)
|
||||
{
|
||||
char id[24];
|
||||
sprintf (id, "cell:%d,%d", row, col);
|
||||
|
||||
char value[24];
|
||||
sprintf (value, "%.2f", data);
|
||||
|
||||
if (mCommify.find (col) != mCommify.end ())
|
||||
mData[id] = commify (value);
|
||||
mData.add (row, col, commify (value));
|
||||
else
|
||||
mData[id] = value;
|
||||
mData.add (row, col, value);
|
||||
|
||||
// Automatically maintain max width.
|
||||
mMaxDataWidth[col] = max (mMaxDataWidth[col], (signed) ::strlen (value));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Table::addCell (int row, int col, double data)
|
||||
void Table::addCell (const int row, const int col, const double data)
|
||||
{
|
||||
char id[24];
|
||||
sprintf (id, "cell:%d,%d", row, col);
|
||||
|
||||
char value[24];
|
||||
sprintf (value, "%.6f", data);
|
||||
|
||||
if (mCommify.find (col) != mCommify.end ())
|
||||
mData[id] = commify (value);
|
||||
mData.add (row, col, commify (value));
|
||||
else
|
||||
mData[id] = value;
|
||||
mData.add (row, col, value);
|
||||
|
||||
// Automatically maintain max width.
|
||||
mMaxDataWidth[col] = max (mMaxDataWidth[col], (signed) ::strlen (value));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Table::setCellColor (int row, int col, Text::color fg, Text::color bg)
|
||||
void Table::setCellColor (const int row, const int col, const Text::color fg, const Text::color bg)
|
||||
{
|
||||
char id[24];
|
||||
sprintf (id, "cell:%d,%d", row, col);
|
||||
|
@ -307,7 +289,7 @@ void Table::setCellColor (int row, int col, Text::color fg, Text::color bg)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Table::setCellFg (int row, int col, Text::color c)
|
||||
void Table::setCellFg (const int row, const int col, const Text::color c)
|
||||
{
|
||||
char id[24];
|
||||
sprintf (id, "cell:%d,%d", row, col);
|
||||
|
@ -315,7 +297,7 @@ void Table::setCellFg (int row, int col, Text::color c)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Table::setCellBg (int row, int col, Text::color c)
|
||||
void Table::setCellBg (const int row, const int col, const Text::color c)
|
||||
{
|
||||
char id[24];
|
||||
sprintf (id, "cell:%d,%d", row, col);
|
||||
|
@ -323,15 +305,17 @@ void Table::setCellBg (int row, int col, Text::color c)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::string Table::getCell (int row, int col)
|
||||
std::string Table::getCell (const int row, const int col)
|
||||
{
|
||||
char id[24];
|
||||
sprintf (id, "cell:%d,%d", row, col);
|
||||
return mData[id];
|
||||
Grid::Cell* c = mData.byRow (row, col);
|
||||
if (c)
|
||||
return (std::string) *c;
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Text::color Table::getFg (int row, int col)
|
||||
Text::color Table::getFg (const int row, const int col)
|
||||
{
|
||||
char idCell[24];
|
||||
sprintf (idCell, "cell:%d,%d", row, col);
|
||||
|
@ -366,7 +350,7 @@ Text::color Table::getHeaderFg (int col)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Text::color Table::getBg (int row, int col)
|
||||
Text::color Table::getBg (const int row, const int col)
|
||||
{
|
||||
char idCell[24];
|
||||
sprintf (idCell, "cell:%d,%d", row, col);
|
||||
|
@ -501,7 +485,7 @@ void Table::calculateColumnWidths ()
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Table::just Table::getJustification (int row, int col)
|
||||
Table::just Table::getJustification (const int row, const int col)
|
||||
{
|
||||
if (mJustification.find (col) != mJustification.end ())
|
||||
return mJustification[col];
|
||||
|
@ -602,10 +586,10 @@ const std::string Table::formatHeader (
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Table::formatCell (
|
||||
int row,
|
||||
int col,
|
||||
int width,
|
||||
int padding,
|
||||
const int row,
|
||||
const int col,
|
||||
const int width,
|
||||
const int padding,
|
||||
std::vector <std::string>& lines,
|
||||
std::string& blank)
|
||||
{
|
||||
|
@ -700,10 +684,10 @@ void Table::formatCell (
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
const std::string Table::formatCell (
|
||||
int row,
|
||||
int col,
|
||||
int width,
|
||||
int padding)
|
||||
const int row,
|
||||
const int col,
|
||||
const int width,
|
||||
const int padding)
|
||||
{
|
||||
assert (width > 0);
|
||||
|
||||
|
@ -855,48 +839,47 @@ void Table::sort (std::vector <int>& order)
|
|||
{
|
||||
keepScanning = false;
|
||||
|
||||
char left[16];
|
||||
sprintf (left, "cell:%d,%d", order[r], mSortColumns[c]);
|
||||
Grid::Cell* left = mData.byRow (order[r], mSortColumns[c]);
|
||||
Grid::Cell* right = mData.byRow (order[r + gap], mSortColumns[c]);
|
||||
if (left == NULL && right != NULL)
|
||||
SWAP
|
||||
|
||||
char right[16];
|
||||
sprintf (right, "cell:%d,%d", order[r + gap], mSortColumns[c]);
|
||||
|
||||
if (mData[left] != mData[right])
|
||||
if (left && right && *left != *right)
|
||||
{
|
||||
switch (mSortOrder[mSortColumns[c]])
|
||||
{
|
||||
case ascendingNumeric:
|
||||
if (::atoi (mData[left].c_str ()) > ::atoi (mData[right].c_str ()))
|
||||
if ((float)*left > (float)*right)
|
||||
SWAP
|
||||
break;
|
||||
|
||||
case descendingNumeric:
|
||||
if (::atoi (mData[left].c_str ()) < ::atoi (mData[right].c_str ()))
|
||||
if ((float)*left < (float)*right)
|
||||
SWAP
|
||||
break;
|
||||
|
||||
case ascendingCharacter:
|
||||
if (mData[left] > mData[right])
|
||||
if ((char)*left > (char)*right)
|
||||
SWAP
|
||||
break;
|
||||
|
||||
case descendingCharacter:
|
||||
if (mData[left] < mData[right])
|
||||
if ((char)*left < (char)*right)
|
||||
SWAP
|
||||
break;
|
||||
|
||||
case ascendingDate:
|
||||
{
|
||||
if (mData[left] != "" && mData[right] == "")
|
||||
if ((std::string)*left != "" && (std::string)*right == "")
|
||||
break;
|
||||
|
||||
else if (mData[left] == "" && mData[right] != "")
|
||||
else if ((std::string)*left == "" && (std::string)*right != "")
|
||||
SWAP
|
||||
|
||||
else
|
||||
{
|
||||
Date dl (mData[left]);
|
||||
Date dr (mData[right]);
|
||||
Date dl ((std::string)*left);
|
||||
Date dr ((std::string)*right);
|
||||
if (dl > dr)
|
||||
SWAP
|
||||
}
|
||||
|
@ -905,16 +888,16 @@ void Table::sort (std::vector <int>& order)
|
|||
|
||||
case descendingDate:
|
||||
{
|
||||
if (mData[left] != "" && mData[right] == "")
|
||||
if ((std::string)*left != "" && (std::string)*right == "")
|
||||
break;
|
||||
|
||||
else if (mData[left] == "" && mData[right] != "")
|
||||
else if ((std::string)*left == "" && (std::string)*right != "")
|
||||
SWAP
|
||||
|
||||
else
|
||||
{
|
||||
Date dl (mData[left]);
|
||||
Date dr (mData[right]);
|
||||
Date dl ((std::string)*left);
|
||||
Date dr ((std::string)*right);
|
||||
if (dl < dr)
|
||||
SWAP
|
||||
}
|
||||
|
@ -922,16 +905,16 @@ void Table::sort (std::vector <int>& order)
|
|||
break;
|
||||
|
||||
case ascendingPriority:
|
||||
if ((mData[left] == "" && mData[right] != "") ||
|
||||
(mData[left] == "M" && mData[right] == "L") ||
|
||||
(mData[left] == "H" && (mData[right] == "L" || mData[right] == "M")))
|
||||
if (((std::string)*left == "" && (std::string)*right != "") ||
|
||||
((std::string)*left == "M" && (std::string)*right == "L") ||
|
||||
((std::string)*left == "H" && ((std::string)*right == "L" || (std::string)*right == "M")))
|
||||
SWAP
|
||||
break;
|
||||
|
||||
case descendingPriority:
|
||||
if ((mData[left] == "" && mData[right] != "") ||
|
||||
(mData[left] == "L" && (mData[right] == "M" || mData[right] == "H")) ||
|
||||
(mData[left] == "M" && mData[right] == "H"))
|
||||
if (((std::string)*left == "" && (std::string)*right != "") ||
|
||||
((std::string)*left == "L" && ((std::string)*right == "M" || (std::string)*right == "H")) ||
|
||||
((std::string)*left == "M" && (std::string)*right == "H"))
|
||||
SWAP
|
||||
break;
|
||||
}
|
||||
|
|
26
src/Table.h
26
src/Table.h
|
@ -65,20 +65,20 @@ public:
|
|||
const std::string render ();
|
||||
|
||||
private:
|
||||
std::string getCell (int, int);
|
||||
Text::color getFg (int, int);
|
||||
Text::color getHeaderFg (int);
|
||||
Text::color getBg (int, int);
|
||||
Text::color getHeaderBg (int);
|
||||
Text::attr getHeaderUnderline (int);
|
||||
int getPadding (int);
|
||||
std::string getCell (const int, const int);
|
||||
Text::color getFg (const int, const int);
|
||||
Text::color getHeaderFg (const int);
|
||||
Text::color getBg (const int, const int);
|
||||
Text::color getHeaderBg (const int);
|
||||
Text::attr getHeaderUnderline (const int);
|
||||
int getPadding (const int);
|
||||
int getIntraPadding ();
|
||||
void calculateColumnWidths ();
|
||||
just getJustification (int, int);
|
||||
just getHeaderJustification (int);
|
||||
const std::string formatHeader (int, int, int);
|
||||
const std::string formatCell (int, int, int, int);
|
||||
void formatCell (int, int, int, int, std::vector <std::string>&, std::string&);
|
||||
just getJustification (const int, const int);
|
||||
just getHeaderJustification (const int);
|
||||
const std::string formatHeader (const int, const int, const int);
|
||||
const std::string formatCell (const int, const int, const int, const int);
|
||||
void formatCell (const int, const int, const int, const int, std::vector <std::string>&, std::string&);
|
||||
void optimize (std::string&);
|
||||
void sort (std::vector <int>&);
|
||||
void clean (std::string&);
|
||||
|
@ -103,7 +103,7 @@ private:
|
|||
|
||||
std::map <int, just> mJustification;
|
||||
std::map <int, bool> mCommify;
|
||||
std::map <std::string, std::string> mData;
|
||||
Grid mData;
|
||||
std::vector <int> mSortColumns;
|
||||
std::map <int, order> mSortOrder;
|
||||
|
||||
|
|
10
src/task.cpp
10
src/task.cpp
|
@ -492,7 +492,7 @@ void handleList (const TDB& tdb, T& task, Config& conf)
|
|||
|
||||
// All criteria match, so add refTask to the output table.
|
||||
int row = table.addRow ();
|
||||
table.addCell (row, 0, (int) i + 1);
|
||||
table.addCell (row, 0, refTask.getId ());
|
||||
table.addCell (row, 1, refTask.getAttribute ("project"));
|
||||
table.addCell (row, 2, refTask.getAttribute ("priority"));
|
||||
table.addCell (row, 3, due);
|
||||
|
@ -665,7 +665,7 @@ void handleSmallList (const TDB& tdb, T& task, Config& conf)
|
|||
|
||||
// All criteria match, so add refTask to the output table.
|
||||
int row = table.addRow ();
|
||||
table.addCell (row, 0, (int) i + 1);
|
||||
table.addCell (row, 0, refTask.getId ());
|
||||
table.addCell (row, 1, refTask.getAttribute ("project"));
|
||||
table.addCell (row, 2, refTask.getAttribute ("priority"));
|
||||
table.addCell (row, 3, refTask.getDescription ());
|
||||
|
@ -1159,7 +1159,7 @@ void handleLongList (const TDB& tdb, T& task, Config& conf)
|
|||
|
||||
// All criteria match, so add refTask to the output table.
|
||||
int row = table.addRow ();
|
||||
table.addCell (row, 0, (int) i + 1);
|
||||
table.addCell (row, 0, refTask.getId ());
|
||||
table.addCell (row, 1, refTask.getAttribute ("project"));
|
||||
table.addCell (row, 2, refTask.getAttribute ("priority"));
|
||||
table.addCell (row, 3, entered);
|
||||
|
@ -1980,7 +1980,7 @@ void handleReportActive (const TDB& tdb, T& task, Config& conf)
|
|||
|
||||
// All criteria match, so add refTask to the output table.
|
||||
int row = table.addRow ();
|
||||
table.addCell (row, 0, (int) i + 1);
|
||||
table.addCell (row, 0, refTask.getId ());
|
||||
table.addCell (row, 1, refTask.getAttribute ("project"));
|
||||
table.addCell (row, 2, refTask.getAttribute ("priority"));
|
||||
table.addCell (row, 3, due);
|
||||
|
@ -2099,7 +2099,7 @@ void handleReportOverdue (const TDB& tdb, T& task, Config& conf)
|
|||
{
|
||||
// All criteria match, so add refTask to the output table.
|
||||
int row = table.addRow ();
|
||||
table.addCell (row, 0, (int) i + 1);
|
||||
table.addCell (row, 0, refTask.getId ());
|
||||
table.addCell (row, 1, refTask.getAttribute ("project"));
|
||||
table.addCell (row, 2, refTask.getAttribute ("priority"));
|
||||
table.addCell (row, 3, due);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue