ColDescription: Minimized use of wrapText

- This is a high-use measure/render method pair, and needs to be quick.
This commit is contained in:
Paul Beckingham 2016-02-23 20:54:52 -05:00
parent fa035c3fde
commit 31f0804207

View file

@ -174,12 +174,12 @@ void ColumnDescription::render (
// ... // ...
if (_style == "default" || if (_style == "default" ||
_style == "combined") _style == "combined")
{
if (task.annotation_count)
{ {
std::map <std::string, std::string> annos; std::map <std::string, std::string> annos;
task.getAnnotations (annos); task.getAnnotations (annos);
if (annos.size ()) for (const auto& i : annos)
{
for (auto& i : annos)
{ {
ISO8601d dt (strtol (i.first.substr (11).c_str (), NULL, 10)); ISO8601d dt (strtol (i.first.substr (11).c_str (), NULL, 10));
description += "\n" + std::string (_indent, ' ') + dt.toString (_dateformat) + " " + i.second; description += "\n" + std::string (_indent, ' ') + dt.toString (_dateformat) + " " + i.second;
@ -189,7 +189,7 @@ void ColumnDescription::render (
std::vector <std::string> raw; std::vector <std::string> raw;
wrapText (raw, description, width, _hyphenate); wrapText (raw, description, width, _hyphenate);
for (auto& i : raw) for (const auto& i : raw)
renderStringLeft (lines, width, color, i); renderStringLeft (lines, width, color, i);
} }
@ -199,18 +199,18 @@ void ColumnDescription::render (
std::vector <std::string> raw; std::vector <std::string> raw;
wrapText (raw, description, width, _hyphenate); wrapText (raw, description, width, _hyphenate);
for (auto& i : raw) for (const auto& i : raw)
renderStringLeft (lines, width, color, i); renderStringLeft (lines, width, color, i);
} }
// This is a description <date> <anno> ... // This is a description <date> <anno> ...
else if (_style == "oneline") else if (_style == "oneline")
{
if (task.annotation_count)
{ {
std::map <std::string, std::string> annos; std::map <std::string, std::string> annos;
task.getAnnotations (annos); task.getAnnotations (annos);
if (annos.size ()) for (const auto& i : annos)
{
for (auto& i : annos)
{ {
ISO8601d dt (strtol (i.first.substr (11).c_str (), NULL, 10)); ISO8601d dt (strtol (i.first.substr (11).c_str (), NULL, 10));
description += " " + dt.toString (_dateformat) + " " + i.second; description += " " + dt.toString (_dateformat) + " " + i.second;
@ -220,7 +220,7 @@ void ColumnDescription::render (
std::vector <std::string> raw; std::vector <std::string> raw;
wrapText (raw, description, width, _hyphenate); wrapText (raw, description, width, _hyphenate);
for (auto& i : raw) for (const auto& i : raw)
renderStringLeft (lines, width, color, i); renderStringLeft (lines, width, color, i);
} }
@ -237,31 +237,26 @@ void ColumnDescription::render (
// This is a description [2] // This is a description [2]
else if (_style == "count") else if (_style == "count")
{ {
std::map <std::string, std::string> annos; if (task.annotation_count)
task.getAnnotations (annos); description += " [" + format (task.annotation_count) + "]";
if (annos.size ())
description += " [" + format ((int) annos.size ()) + "]";
std::vector <std::string> raw; std::vector <std::string> raw;
wrapText (raw, description, width, _hyphenate); wrapText (raw, description, width, _hyphenate);
for (auto& i : raw) for (const auto& i : raw)
renderStringLeft (lines, width, color, i); renderStringLeft (lines, width, color, i);
} }
// This is a des... [2] // This is a des... [2]
else if (_style == "truncated_count") else if (_style == "truncated_count")
{ {
std::map <std::string, std::string> annos;
task.getAnnotations (annos);
int len = utf8_width (description); int len = utf8_width (description);
std::string annos_count; std::string annos_count;
int len_annos = 0; int len_annos = 0;
if (task.annotation_count)
if (annos.size ())
{ {
annos_count = " [" + format ((int) annos.size ()) + "]"; annos_count = " [" + format (task.annotation_count) + "]";
len_annos = utf8_width (annos_count); len_annos = utf8_width (annos_count);
len += len_annos; len += len_annos;
} }