From 61e1401073073269208873abb180f34108ff3e4f Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 5 Apr 2015 16:05:43 -0400 Subject: [PATCH] Performance: Only measures the first fixed-width column row --- ChangeLog | 3 +++ src/ViewTask.cpp | 5 +++++ src/ViewText.cpp | 5 +++++ src/columns/ColDepends.cpp | 11 +++++++++-- src/columns/ColRecur.cpp | 4 ++-- src/columns/ColStart.cpp | 4 ++-- src/columns/ColTags.cpp | 11 +++++++++-- src/columns/ColUDA.cpp | 4 ++-- src/columns/Column.cpp | 17 ++++++++++------- src/columns/Column.h | 2 ++ 10 files changed, 49 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 437248271..5c68e9f8c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 --------------------------- diff --git a/src/ViewTask.cpp b/src/ViewTask.cpp index 5a089f12d..5168aae83 100644 --- a/src/ViewTask.cpp +++ b/src/ViewTask.cpp @@ -143,6 +143,11 @@ std::string ViewTask::render (std::vector & data, std::vector & 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) diff --git a/src/ViewText.cpp b/src/ViewText.cpp index c50c1ca5b..083578856 100644 --- a/src/ViewText.cpp +++ b/src/ViewText.cpp @@ -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); diff --git a/src/columns/ColDepends.cpp b/src/columns/ColDepends.cpp index cdea60dfb..345562761 100644 --- a/src/columns/ColDepends.cpp +++ b/src/columns/ColDepends.cpp @@ -83,8 +83,15 @@ void ColumnDepends::measure (Task& task, unsigned int& minimum, unsigned int& ma std::vector 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") { diff --git a/src/columns/ColRecur.cpp b/src/columns/ColRecur.cpp index d80e4e0d9..73436d9c0 100644 --- a/src/columns/ColRecur.cpp +++ b/src/columns/ColRecur.cpp @@ -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); diff --git a/src/columns/ColStart.cpp b/src/columns/ColStart.cpp index ca18e2694..ce0ea2fb1 100644 --- a/src/columns/ColStart.cpp +++ b/src/columns/ColStart.cpp @@ -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); diff --git a/src/columns/ColTags.cpp b/src/columns/ColTags.cpp index 32396f52b..5c3324e88 100644 --- a/src/columns/ColTags.cpp +++ b/src/columns/ColTags.cpp @@ -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") { diff --git a/src/columns/ColUDA.cpp b/src/columns/ColUDA.cpp index ede3e8628..5fc023866 100644 --- a/src/columns/ColUDA.cpp +++ b/src/columns/ColUDA.cpp @@ -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); diff --git a/src/columns/Column.cpp b/src/columns/Column.cpp index 101977825..2f9dc3144 100644 --- a/src/columns/Column.cpp +++ b/src/columns/Column.cpp @@ -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; diff --git a/src/columns/Column.h b/src/columns/Column.h index e59547c3d..a6c09d367 100644 --- a/src/columns/Column.h +++ b/src/columns/Column.h @@ -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 styles () const { return _styles; } std::vector examples () const { return _examples; } @@ -76,6 +77,7 @@ protected: std::string _report; bool _modifiable; bool _uda; + bool _fixed_width; std::vector _styles; std::vector _examples; };