Skip to content

Commit

Permalink
* Replaced quite a lot of unnecessary size() calls on STL containers
Browse files Browse the repository at this point in the history
   with the more describtive and faster empty() method.
  • Loading branch information
mwanner committed Sep 17, 2008
1 parent 1c80eca commit d4521e2
Show file tree
Hide file tree
Showing 38 changed files with 114 additions and 115 deletions.
2 changes: 1 addition & 1 deletion HACKING
Expand Up @@ -354,7 +354,7 @@ An invariant failure indicates that there is a bug in monotone. e.g.
User naughtiness handles error conditions where the user has asked monotone
to do something it is unable to. e.g.

N(completions.size() != 0,
N(!completions.empty(),
F("no match for selection '%s'") % str);

Error conditions handle most other error cases, where monotone is unable to
Expand Down
4 changes: 4 additions & 0 deletions NEWS
Expand Up @@ -17,6 +17,10 @@
would reinitialize the database. This was rather slow, so
monotone will now keep the database open between commands.

- Small performance gains especially for annotate by replacing
'size() == 0' and similar checks with the faster 'empty()'
STL method.

New features

- New 'mtn ls duplicates' command which lets you list
Expand Down
6 changes: 3 additions & 3 deletions asciik.cc
Expand Up @@ -245,7 +245,7 @@ asciik::draw(size_t const curr_items,
if (num_lines < 2)
lines.push_back(string(""));
// ignore empty lines at the end
while ((num_lines > 2) && (lines[num_lines - 1].size() == 0))
while ((num_lines > 2) && (lines[num_lines - 1].empty()))
--num_lines;

// prints it out
Expand Down Expand Up @@ -314,7 +314,7 @@ asciik::try_draw(vector<revision_id> const & next_row,
preservation_crosses.begin(), preservation_crosses.end(),
parent_crosses.begin(), parent_crosses.end(),
insert_iterator<set<size_t> >(intersection_crosses, intersection_crosses.begin()));
if (intersection_crosses.size() > 0)
if (!intersection_crosses.empty())
return false;

set<pair<size_t, size_t> > links(preservation_links);
Expand Down Expand Up @@ -360,7 +360,7 @@ asciik::print(revision_id const & rev,
curr_row = no_ghost;
else if (try_draw(next_row, curr_loc, parents, annotation))
curr_row = next_row;
else if (new_revs.size() == 0) // this line has disappeared
else if (new_revs.empty()) // this line has disappeared
{
vector<revision_id> extra_ghost(next_row);
I(curr_loc < extra_ghost.size());
Expand Down
4 changes: 2 additions & 2 deletions automate.cc
Expand Up @@ -966,7 +966,7 @@ inventory_determine_changes(inventory_item const & item, roster_t const & old_ro
if (item.new_node.type == path::file)
changes.push_back("content");

if (item.new_node.attrs.size() > 0)
if (!item.new_node.attrs.empty())
changes.push_back("attrs");
}
}
Expand Down Expand Up @@ -2150,7 +2150,7 @@ CMD_AUTOMATE(get_db_variables, N_("[DOMAIN]"),
if (cur_domain != i->first.first)
{
// check if we need to print a previous stanza
if (st.entries.size() > 0)
if (!st.entries.empty())
{
pr.print_stanza(st);
st.entries.clear();
Expand Down
2 changes: 1 addition & 1 deletion cert.cc
Expand Up @@ -409,7 +409,7 @@ guess_branch(options & opts, project_t & project,
set<branch_name> branches;
project.get_revision_branches(ident, branches);

N(branches.size() != 0,
N(!branches.empty(),
F("no branch certs found for revision %s, "
"please provide a branch name") % ident);

Expand Down
8 changes: 4 additions & 4 deletions cmd_automate.cc
Expand Up @@ -87,7 +87,7 @@ CMD_AUTOMATE(interface_version, "",
"",
options::opts::none)
{
N(args.size() == 0,
N(args.empty(),
F("no arguments needed"));

output << interface_version << '\n';
Expand Down Expand Up @@ -343,7 +343,7 @@ CMD_AUTOMATE(stdio, "",
"",
options::opts::automate_stdio_size)
{
N(args.size() == 0,
N(args.empty(),
F("no arguments needed"));

database db(app);
Expand Down Expand Up @@ -384,7 +384,7 @@ CMD_AUTOMATE(stdio, "",
set< command_id > matches =
CMD_REF(automate)->complete_command(id);

if (matches.size() == 0)
if (matches.empty())
{
N(false, F("no completions for this command"));
}
Expand Down Expand Up @@ -475,7 +475,7 @@ LUAEXT(mtn_automate, )
set< commands::command_id > matches =
CMD_REF(automate)->complete_command(id);

if (matches.size() == 0)
if (matches.empty())
{
N(false, F("no completions for this command"));
}
Expand Down
10 changes: 5 additions & 5 deletions cmd_diff_log.cc
Expand Up @@ -365,7 +365,7 @@ prepare_diff(app_state & app,
N(app.opts.revision_selectors.size() <= 2,
F("more than two revisions given"));

if (app.opts.revision_selectors.size() == 0)
if (app.opts.revision_selectors.empty())
{
roster_t old_roster, restricted_roster, new_roster;
revision_id old_rid;
Expand Down Expand Up @@ -509,7 +509,7 @@ CMD(diff, "diff", "di", CMD_REF(informative), N_("[PATH]..."),
vector<string> lines;
split_into_lines(summary(), lines);
cout << "#\n";
if (summary().size() > 0)
if (!summary().empty())
{
cout << revs << "#\n";
for (vector<string>::iterator i = lines.begin();
Expand Down Expand Up @@ -644,7 +644,7 @@ CMD(log, "log", "", CMD_REF(informative), N_("[FILE] ..."),
frontier_t frontier(rev_cmp(!(next>0)));
revision_id first_rid; // for mapping paths to node ids when restricted

if (app.opts.from.size() == 0)
if (app.opts.from.empty())
{
workspace work(app,
F("try passing a --from revision to start at"));
Expand Down Expand Up @@ -680,10 +680,10 @@ CMD(log, "log", "", CMD_REF(informative), N_("[FILE] ..."),

node_restriction mask;

if (args.size() > 0)
if (!args.empty())
{
// User wants to trace only specific files
if (app.opts.from.size() == 0)
if (app.opts.from.empty())
{
workspace work(app);
roster_t new_roster;
Expand Down
18 changes: 7 additions & 11 deletions cmd_files.cc
Expand Up @@ -146,7 +146,7 @@ CMD(annotate, "annotate", "", CMD_REF(informative), N_("PATH"),
L(FL("annotate file '%s'") % file);

roster_t roster;
if (app.opts.revision_selectors.size() == 0)
if (app.opts.revision_selectors.empty())
{
// What this _should_ do is calculate the current workspace roster
// and/or revision and hand that to do_annotate. This should just
Expand Down Expand Up @@ -198,19 +198,15 @@ CMD(identify, "identify", "", CMD_REF(debug), N_("[PATH]"),
"one from the standard input is calculated."),
options::opts::none)
{
if (!(args.size() == 0 || args.size() == 1))
if (args.size() > 1)
throw usage(execid);

data dat;

if (args.size() == 1)
{
read_data_for_command_line(idx(args, 0), dat);
}
if (args.empty())
read_data_stdin(dat);
else
{
read_data_stdin(dat);
}
read_data_for_command_line(idx(args, 0), dat);

id ident;
calculate_ident(dat, ident);
Expand Down Expand Up @@ -296,7 +292,7 @@ CMD(cat, "cat", "", CMD_REF(informative),

database db(app);
revision_id rid;
if (app.opts.revision_selectors.size() == 0)
if (app.opts.revision_selectors.empty())
{
workspace work(app);
parent_map parents;
Expand Down Expand Up @@ -363,7 +359,7 @@ CMD_AUTOMATE(get_file_of, N_("FILENAME"),
database db(app);

revision_id rid;
if (app.opts.revision_selectors.size() == 0)
if (app.opts.revision_selectors.empty())
{
workspace work(app);

Expand Down
2 changes: 1 addition & 1 deletion cmd_key_cert.cc
Expand Up @@ -122,7 +122,7 @@ CMD(ssh_agent_export, "ssh_agent_export", "", CMD_REF(key_and_cert),
rsa_keypair_id id;
get_user_key(app.opts, app.lua, db, keys, id);

if (args.size() == 0)
if (args.empty())
keys.export_key_for_agent(id, cout);
else
{
Expand Down
23 changes: 11 additions & 12 deletions cmd_list.cc
Expand Up @@ -136,7 +136,7 @@ CMD(certs, "certs", "", CMD_REF(list), "ID",

vector<string> lines;
split_into_lines(washed, lines);
std::string value_first_line = lines.size() > 0 ? idx(lines, 0) : "";
std::string value_first_line = lines.empty() ? "" : idx(lines, 0);

cout << string(guess_terminal_width(), '-') << '\n'
<< (i18n_format(str)
Expand All @@ -149,7 +149,7 @@ CMD(certs, "certs", "", CMD_REF(list), "ID",
cout << (i18n_format(extra_str) % idx(lines, i));
}

if (certs.size() > 0)
if (!certs.empty())
cout << '\n';

guard.commit();
Expand All @@ -161,7 +161,7 @@ CMD(duplicates, "duplicates", "", CMD_REF(list), "",
"",
options::opts::revision)
{
if (args.size() != 0)
if (!args.empty())
throw usage(execid);

revision_id rev_id;
Expand All @@ -172,7 +172,7 @@ CMD(duplicates, "duplicates", "", CMD_REF(list), "",
N(app.opts.revision_selectors.size() <= 1,
F("more than one revision given"));

if (app.opts.revision_selectors.size() == 0)
if (app.opts.revision_selectors.empty())
{
workspace work(app);
temp_node_id_source nis;
Expand Down Expand Up @@ -302,7 +302,7 @@ CMD(keys, "keys", "", CMD_REF(list), "[PATTERN]",
}
}

if (pubkeys.size() > 0)
if (!pubkeys.empty())
{
cout << "\n[public keys]\n";
for (map<rsa_keypair_id, bool>::iterator i = pubkeys.begin();
Expand Down Expand Up @@ -333,7 +333,7 @@ CMD(keys, "keys", "", CMD_REF(list), "[PATTERN]",
cout << '\n';
}

if (privkeys.size() > 0)
if (!privkeys.empty())
{
cout << "\n[private keys]\n";
for (vector<rsa_keypair_id>::iterator i = privkeys.begin();
Expand All @@ -358,10 +358,9 @@ CMD(keys, "keys", "", CMD_REF(list), "[PATTERN]",
}
}

if (pubkeys.size() == 0 &&
privkeys.size() == 0)
if (pubkeys.empty() && privkeys.empty())
{
if (args.size() == 0)
if (args.empty())
P(F("no keys found"));
else
W(F("no keys found matching '%s'") % idx(args, 0)());
Expand Down Expand Up @@ -400,7 +399,7 @@ CMD(epochs, "epochs", "", CMD_REF(list), "[BRANCH [...]]",
map<branch_name, epoch_data> epochs;
db.get_epochs(epochs);

if (args.size() == 0)
if (args.empty())
{
for (map<branch_name, epoch_data>::const_iterator
i = epochs.begin();
Expand Down Expand Up @@ -447,7 +446,7 @@ CMD(vars, "vars", "", CMD_REF(list), "[DOMAIN]",
{
bool filterp;
var_domain filter;
if (args.size() == 0)
if (args.empty())
{
filterp = false;
}
Expand Down Expand Up @@ -678,7 +677,7 @@ CMD_AUTOMATE(keys, "",
"",
options::opts::none)
{
N(args.size() == 0,
N(args.empty(),
F("no arguments needed"));

database db(app);
Expand Down

0 comments on commit d4521e2

Please sign in to comment.