Performance

- It it not necessary to make a copy of all configuration variable names, if the
  Config::const_iterator is sufficient.

(cherry picked from commit 5708cb90780f1f6c8f58f5b549796c4af612b1ab)
This commit is contained in:
Paul Beckingham 2013-05-26 11:40:18 -04:00
parent c16a735040
commit 7b89bc92e1
10 changed files with 95 additions and 128 deletions

View file

@ -105,25 +105,21 @@ void Hooks::initialize ()
bool big_red_switch = context.config.getBoolean ("extensions");
if (big_red_switch)
{
std::vector <std::string> vars;
context.config.all (vars);
std::vector <std::string>::iterator it;
for (it = vars.begin (); it != vars.end (); ++it)
Config::const_iterator it;
for (it = context.config.begin (); it != context.config.end (); ++it)
{
std::string type;
std::string name;
std::string value;
// "<type>.<name>"
Nibbler n (*it);
Nibbler n (it->first);
if (n.getUntil ('.', type) &&
type == "hook" &&
n.skip ('.') &&
n.getUntilEOS (name))
{
std::string value = context.config.get (*it);
Nibbler n (value);
Nibbler n (it->second);
// <path>:<function> [, ...]
while (!n.depleted ())
@ -141,7 +137,7 @@ void Hooks::initialize ()
(void) n.skip (',');
}
else
; // Was: throw std::string (format ("Malformed hook definition '{1}'.", *it));
; // Was: throw std::string (format ("Malformed hook definition '{1}'.", it->first));
}
}
}

View file

@ -1316,19 +1316,16 @@ void Task::validate (bool applyDefault /* = true */)
if (applyDefault)
{
// Gather a list of all UDAs with a .default value
std::vector <std::string> names;
context.config.all (names);
std::vector <std::string> udas;
std::vector <std::string>::iterator name;
for (name = names.begin (); name != names.end (); ++name)
Config::const_iterator var;
for (var = context.config.begin (); var != context.config.end (); ++var)
{
if (name->substr (0, 4) == "uda." &&
name->find (".default") != std::string::npos)
if (var->first.substr (0, 4) == "uda." &&
var->first.find (".default") != std::string::npos)
{
std::string::size_type period = name->find ('.', 4);
std::string::size_type period = var->first.find ('.', 4);
if (period != std::string::npos)
udas.push_back (name->substr (4, period - 4));
udas.push_back (var->first.substr (4, period - 4));
}
}

View file

@ -151,17 +151,15 @@ void Column::uda (std::map <std::string, Column*>& all)
{
// For each UDA, instantiate and initialize ColumnUDA().
std::map <std::string, int> udas;
std::vector <std::string> names;
context.config.all (names);
std::vector <std::string>::iterator i;
for (i = names.begin (); i != names.end (); ++i)
Config::const_iterator i;
for (i = context.config.begin (); i != context.config.end (); ++i)
{
if (i->substr (0, 4) == "uda.")
if (i->first.substr (0, 4) == "uda.")
{
std::string::size_type period = 4;
if ((period = i->find ('.', period)) != std::string::npos)
udas[i->substr (4, period - 4)] = 0;
if ((period = i->first.find ('.', period)) != std::string::npos)
udas[i->first.substr (4, period - 4)] = 0;
}
}

View file

@ -351,22 +351,19 @@ int CmdCalendar::execute (std::string& output)
// Table with holiday information
if (context.config.get ("calendar.holidays") == "full")
{
std::vector <std::string> holidays;
context.config.all (holidays);
ViewText holTable;
holTable.width (context.getWidth ());
holTable.add (Column::factory ("string", STRING_CMD_CAL_LABEL_DATE));
holTable.add (Column::factory ("string", STRING_CMD_CAL_LABEL_HOL));
std::vector <std::string>::iterator it;
Config::const_iterator it;
std::map <time_t, std::vector<std::string> > hm; // we need to store multiple holidays per day
for (it = holidays.begin (); it != holidays.end (); ++it)
if (it->substr (0, 8) == "holiday.")
if (it->substr (it->size () - 4) == "name")
for (it = context.config.begin (); it != context.config.end (); ++it)
if (it->first.substr (0, 8) == "holiday.")
if (it->first.substr (it->first.size () - 4) == "name")
{
std::string holName = context.config.get ("holiday." + it->substr (8, it->size () - 13) + ".name");
std::string holDate = context.config.get ("holiday." + it->substr (8, it->size () - 13) + ".date");
std::string holName = context.config.get ("holiday." + it->first.substr (8, it->first.size () - 13) + ".name");
std::string holDate = context.config.get ("holiday." + it->first.substr (8, it->first.size () - 13) + ".date");
Date hDate (holDate.c_str (), context.config.get ("dateformat.holiday"));
if (date_after < hDate && hDate < date_before)
@ -526,14 +523,12 @@ std::string CmdCalendar::renderMonths (
// colorize holidays
if (context.config.get ("calendar.holidays") != "none")
{
std::vector <std::string> holidays;
context.config.all (holidays);
std::vector <std::string>::iterator hol;
for (hol = holidays.begin (); hol != holidays.end (); ++hol)
if (hol->substr (0, 8) == "holiday.")
if (hol->substr (hol->size () - 4) == "date")
Config::const_iterator hol;
for (hol = context.config.begin (); hol != context.config.end (); ++hol)
if (hol->first.substr (0, 8) == "holiday.")
if (hol->first.substr (hol->first.size () - 4) == "date")
{
std::string value = context.config.get (*hol);
std::string value = hol->second;
Date holDate (value.c_str (), context.config.get ("dateformat.holiday"));
if (holDate.day () == d &&
holDate.month () == months[mpl] &&

View file

@ -69,27 +69,24 @@ int CmdColor::execute (std::string& output)
{
out << "\n" << STRING_CMD_COLOR_HERE << "\n";
std::vector <std::string> all;
context.config.all (all);
ViewText view;
view.width (context.getWidth ());
view.add (Column::factory ("string", STRING_CMD_COLOR_COLOR));
view.add (Column::factory ("string", STRING_CMD_COLOR_DEFINITION));
std::vector <std::string>::iterator item;
for (item = all.begin (); item != all.end (); ++item)
Config::const_iterator item;
for (item = context.config.begin (); item != context.config.end (); ++item)
{
// Skip items with 'color' in their name, that are not referring to
// actual colors.
if (*item != "_forcecolor" &&
*item != "color" &&
item->find ("color") == 0)
if (item->first != "_forcecolor" &&
item->first != "color" &&
item->first.find ("color") == 0)
{
Color color (context.config.get (*item));
Color color (context.config.get (item->first));
int row = view.addRow ();
view.set (row, 0, *item, color);
view.set (row, 1, context.config.get (*item), color);
view.set (row, 0, item->first, color);
view.set (row, 1, item->second, color);
}
}

View file

@ -51,15 +51,12 @@ int CmdReports::execute (std::string& output)
std::vector <std::string> reports;
// Add custom reports.
std::vector <std::string> vars;
context.config.all (vars);
std::vector <std::string>::iterator i;
for (i = vars.begin (); i != vars.end (); ++i)
Config::const_iterator i;
for (i = context.config.begin (); i != context.config.end (); ++i)
{
if (i->substr (0, 7) == "report.")
if (i->first.substr (0, 7) == "report.")
{
std::string report = i->substr (7);
std::string report = i->first.substr (7);
std::string::size_type columns = report.find (".columns");
if (columns != std::string::npos)
reports.push_back (report.substr (0, columns));

View file

@ -214,38 +214,35 @@ int CmdShow::execute (std::string& output)
// is redirected to a file, or stdout is not a tty.
recognized += "_forcecolor ";
std::vector <std::string> all;
context.config.all (all);
std::vector <std::string> unrecognized;
std::vector <std::string>::iterator i;
for (i = all.begin (); i != all.end (); ++i)
Config::const_iterator i;
for (i = context.config.begin (); i != context.config.end (); ++i)
{
// Disallow partial matches by tacking a leading and trailing space on each
// variable name.
std::string pattern = " " + *i + " ";
std::string pattern = " " + i->first + " ";
if (recognized.find (pattern) == std::string::npos)
{
// These are special configuration variables, because their name is
// dynamic.
if (i->substr (0, 14) != "color.keyword." &&
i->substr (0, 14) != "color.project." &&
i->substr (0, 10) != "color.tag." &&
i->substr (0, 10) != "color.uda." &&
i->substr (0, 8) != "holiday." &&
i->substr (0, 7) != "report." &&
i->substr (0, 6) != "alias." &&
i->substr (0, 5) != "hook." &&
i->substr (0, 5) != "push." &&
i->substr (0, 5) != "pull." &&
i->substr (0, 6) != "merge." &&
i->substr (0, 4) != "uda." &&
i->substr (0, 4) != "default." &&
i->substr (0, 21) != "urgency.user.project." &&
i->substr (0, 17) != "urgency.user.tag." &&
i->substr (0, 12) != "urgency.uda.")
if (i->first.substr (0, 14) != "color.keyword." &&
i->first.substr (0, 14) != "color.project." &&
i->first.substr (0, 10) != "color.tag." &&
i->first.substr (0, 10) != "color.uda." &&
i->first.substr (0, 8) != "holiday." &&
i->first.substr (0, 7) != "report." &&
i->first.substr (0, 6) != "alias." &&
i->first.substr (0, 5) != "hook." &&
i->first.substr (0, 5) != "push." &&
i->first.substr (0, 5) != "pull." &&
i->first.substr (0, 6) != "merge." &&
i->first.substr (0, 4) != "uda." &&
i->first.substr (0, 4) != "default." &&
i->first.substr (0, 21) != "urgency.user.project." &&
i->first.substr (0, 17) != "urgency.user.tag." &&
i->first.substr (0, 12) != "urgency.uda.")
{
unrecognized.push_back (*i);
unrecognized.push_back (i->first);
}
}
}
@ -255,9 +252,9 @@ int CmdShow::execute (std::string& output)
Config default_config;
default_config.setDefaults ();
for (i = all.begin (); i != all.end (); ++i)
if (context.config.get (*i) != default_config.get (*i))
default_values.push_back (*i);
for (i = context.config.begin (); i != context.config.end (); ++i)
if (i->second != default_config.get (i->first))
default_values.push_back (i->first);
// Create output view.
ViewText view;
@ -281,29 +278,29 @@ int CmdShow::execute (std::string& output)
section = "";
std::string::size_type loc;
for (i = all.begin (); i != all.end (); ++i)
for (i = context.config.begin (); i != context.config.end (); ++i)
{
loc = i->find (section, 0);
loc = i->first.find (section, 0);
if (loc != std::string::npos)
{
// Look for unrecognized.
Color color;
if (std::find (unrecognized.begin (), unrecognized.end (), *i) != unrecognized.end ())
if (std::find (unrecognized.begin (), unrecognized.end (), i->first) != unrecognized.end ())
{
issue_error = true;
color = error;
}
else if (std::find (default_values.begin (), default_values.end (), *i) != default_values.end ())
else if (std::find (default_values.begin (), default_values.end (), i->first) != default_values.end ())
{
issue_warning = true;
color = warning;
}
std::string value = context.config.get (*i);
std::string value = i->second;
// hide sensible information
if ( (i->substr (0, 5) == "push." ||
i->substr (0, 5) == "pull." ||
i->substr (0, 6) == "merge.") && (i->find (".uri") != std::string::npos) ) {
if ( (i->first.substr (0, 5) == "push." ||
i->first.substr (0, 5) == "pull." ||
i->first.substr (0, 6) == "merge.") && (i->first.find (".uri") != std::string::npos) ) {
Uri uri (value);
uri.parse ();
@ -311,7 +308,7 @@ int CmdShow::execute (std::string& output)
}
int row = view.addRow ();
view.set (row, 0, *i, color);
view.set (row, 0, i->first, color);
view.set (row, 1, value, color);
}
}
@ -336,6 +333,7 @@ int CmdShow::execute (std::string& output)
{
out << STRING_CMD_SHOW_UNREC << "\n";
std::vector <std::string>::iterator i;
for (i = unrecognized.begin (); i != unrecognized.end (); ++i)
out << " " << *i << "\n";
@ -381,7 +379,7 @@ int CmdShow::execute (std::string& output)
// Verify installation. This is mentioned in the documentation as the way
// to ensure everything is properly installed.
if (all.size () == 0)
if (context.config.size () == 0)
{
out << STRING_CMD_SHOW_EMPTY << "\n";
rc = 1;

View file

@ -53,19 +53,16 @@ int CmdUDAs::execute (std::string& output)
int rc = 0;
std::stringstream out;
std::vector <std::string> names;
context.config.all (names);
std::vector <std::string> udas;
std::vector <std::string>::iterator name;
for (name = names.begin (); name != names.end (); ++name)
Config::const_iterator name;
for (name = context.config.begin (); name != context.config.end (); ++name)
{
if (name->substr (0, 4) == "uda." &&
name->find (".type") != std::string::npos)
if (name->first.substr (0, 4) == "uda." &&
name->first.find (".type") != std::string::npos)
{
std::string::size_type period = name->find ('.', 4);
std::string::size_type period = name->first.find ('.', 4);
if (period != std::string::npos)
udas.push_back (name->substr (4, period - 4));
udas.push_back (name->first.substr (4, period - 4));
}
}
@ -182,19 +179,16 @@ CmdCompletionUDAs::CmdCompletionUDAs ()
////////////////////////////////////////////////////////////////////////////////
int CmdCompletionUDAs::execute (std::string& output)
{
std::vector <std::string> names;
context.config.all (names);
std::vector <std::string> udas;
std::vector <std::string>::iterator name;
for (name = names.begin (); name != names.end (); ++name)
Config::const_iterator name;
for (name = context.config.begin (); name != context.config.end (); ++name)
{
if (name->substr (0, 4) == "uda." &&
name->find (".type") != std::string::npos)
if (name->first.substr (0, 4) == "uda." &&
name->first.find (".type") != std::string::npos)
{
std::string::size_type period = name->find ('.', 4);
std::string::size_type period = name->first.find ('.', 4);
if (period != std::string::npos)
udas.push_back (name->substr (4, period - 4));
udas.push_back (name->first.substr (4, period - 4));
}
}

View file

@ -168,16 +168,13 @@ void Command::factory (std::map <std::string, Command*>& all)
c = new CmdZshCompletionUuids (); all[c->keyword ()] = c;
// Instantiate a command object for each custom report.
std::vector <std::string> variables;
context.config.all (variables);
std::vector <std::string> reports;
std::vector <std::string>::iterator i;
for (i = variables.begin (); i != variables.end (); ++i)
Config::const_iterator i;
for (i = context.config.begin (); i != context.config.end (); ++i)
{
if (i->substr (0, 7) == "report.")
if (i->first.substr (0, 7) == "report.")
{
std::string report = i->substr (7);
std::string report = i->first.substr (7);
std::string::size_type columns = report.find (".columns");
if (columns != std::string::npos)
reports.push_back (report.substr (0, columns));

View file

@ -47,17 +47,15 @@ void initializeColorRules ()
// Load all the configuration values, filter to only the ones that begin with
// "color.", then store name/value in gsColor, and name in rules.
std::vector <std::string> rules;
std::vector <std::string> variables;
context.config.all (variables);
std::vector <std::string>::iterator v;
for (v = variables.begin (); v != variables.end (); ++v)
Config::const_iterator v;
for (v = context.config.begin (); v != context.config.end (); ++v)
{
if (v->substr (0, 6) == "color.")
if (v->first.substr (0, 6) == "color.")
{
Color c (context.config.get (*v));
gsColor[*v] = c;
Color c (v->second);
gsColor[v->first] = c;
rules.push_back (*v);
rules.push_back (v->first);
}
}