Performance: Only measures the first fixed-width column row

This commit is contained in:
Paul Beckingham 2015-04-05 16:05:43 -04:00
parent a883c5ca41
commit 61e1401073
10 changed files with 49 additions and 17 deletions

View file

@ -26,6 +26,9 @@
- Disable hooks in bash completion script. Hooks were previously able to
abort processing or output interfering data, breaking completion.
- Fix "task add due:tomorrow+3days" failing to work without spaces.
- Performance improvements:
+ Stops after measuring a fixed-width column format.
+ Reduced number of std::string copies.
------ current release ---------------------------

View file

@ -143,6 +143,11 @@ std::string ViewTask::render (std::vector <Task>& data, std::vector <int>& seque
if (min > global_min) global_min = min;
if (ideal > global_ideal) global_ideal = ideal;
// If a fixed-width column was just measured, there is no point repeating
// the measurement for all tasks.
if (_columns[i]->is_fixed_width ())
break;
}
if (print_empty_columns || global_min != 0)

View file

@ -132,6 +132,11 @@ std::string ViewText::render ()
if (min > global_min) global_min = min;
if (ideal > global_ideal) global_ideal = ideal;
// If a fixed-width column was just measured, there is no point repeating
// the measurement for all tasks.
if (_columns[i]->is_fixed_width ())
break;
}
minimal.push_back (global_min);

View file

@ -83,8 +83,15 @@ void ColumnDepends::measure (Task& task, unsigned int& minimum, unsigned int& ma
std::vector <Task> blocking;
dependencyGetBlocking (task, blocking);
if (_style == "indicator") minimum = maximum = utf8_width (context.config.get ("dependency.indicator"));
else if (_style == "count") minimum = maximum = 2 + format ((int) blocking.size ()).length ();
if (_style == "indicator")
{
minimum = maximum = utf8_width (context.config.get ("dependency.indicator"));
_fixed_width = true;
}
else if (_style == "count")
{
minimum = maximum = 2 + format ((int) blocking.size ()).length ();
}
else if (_style == "default" ||
_style == "list")
{

View file

@ -90,8 +90,8 @@ void ColumnRecur::measure (Task& task, unsigned int& minimum, unsigned int& maxi
}
else if (_style == "indicator")
{
if (task.has (_name))
minimum = maximum = utf8_width (context.config.get ("recurrence.indicator"));
minimum = maximum = utf8_width (context.config.get ("recurrence.indicator"));
_fixed_width = true;
}
else
throw format (STRING_COLUMN_BAD_FORMAT, _name, _style);

View file

@ -76,8 +76,8 @@ void ColumnStart::measure (Task& task, unsigned int& minimum, unsigned int& maxi
{
if (_style == "active")
{
if (! task.has ("end"))
minimum = maximum = utf8_width (context.config.get ("active.indicator"));
minimum = maximum = utf8_width (context.config.get ("active.indicator"));
_fixed_width = true;
}
else
ColumnDate::measure (task, minimum, maximum);

View file

@ -88,8 +88,15 @@ void ColumnTags::measure (Task& task, unsigned int& minimum, unsigned int& maxim
if (task.has (_name))
{
if (_style == "indicator") minimum = maximum = utf8_width (context.config.get ("tag.indicator"));
else if (_style == "count") minimum = maximum = 3;
if (_style == "indicator")
{
minimum = maximum = utf8_width (context.config.get ("tag.indicator"));
_fixed_width = true;
}
else if (_style == "count")
{
minimum = maximum = 3;
}
else if (_style == "default" ||
_style == "list")
{

View file

@ -120,8 +120,8 @@ void ColumnUDA::measure (Task& task, unsigned int& minimum, unsigned int& maximu
}
else if (_style == "indicator")
{
if (task.has (_name))
minimum = maximum = utf8_width (context.config.get ("uda." + _name + ".indicator"));
minimum = maximum = utf8_width (context.config.get ("uda." + _name + ".indicator"));
_fixed_width = true;
}
else
throw format (STRING_COLUMN_BAD_FORMAT, _name, _style);

View file

@ -208,19 +208,21 @@ Column::Column ()
, _report ("")
, _modifiable (true)
, _uda (false)
, _fixed_width (false)
{
}
////////////////////////////////////////////////////////////////////////////////
Column::Column (const Column& other)
{
_name = other._name;
_type = other._type;
_style = other._style;
_label = other._label;
_label = other._report;
_modifiable = other._modifiable;
_uda = other._uda;
_name = other._name;
_type = other._type;
_style = other._style;
_label = other._label;
_label = other._report;
_modifiable = other._modifiable;
_uda = other._uda;
_fixed_width = other._fixed_width;
}
////////////////////////////////////////////////////////////////////////////////
@ -235,6 +237,7 @@ Column& Column::operator= (const Column& other)
_report = other._report;
_modifiable = other._modifiable;
_uda = other._uda;
_fixed_width = other._fixed_width;
}
return *this;

View file

@ -52,6 +52,7 @@ public:
const std::string& type () const { return _type; }
bool modifiable () const { return _modifiable; }
bool is_uda () const { return _uda; }
bool is_fixed_width () const { return _fixed_width;}
std::vector <std::string> styles () const { return _styles; }
std::vector <std::string> examples () const { return _examples; }
@ -76,6 +77,7 @@ protected:
std::string _report;
bool _modifiable;
bool _uda;
bool _fixed_width;
std::vector <std::string> _styles;
std::vector <std::string> _examples;
};