Skip to content

Commit

Permalink
Change iterators to use prefix ++ since it is more efficient.
Browse files Browse the repository at this point in the history
This patch changes all the iterator code to use a prefix ++ instead
of postfix since it is more efficient (no need for a temporary). It
is likely that the compiler could optimize this away, but lets make
it efficient from the start.
  • Loading branch information
caryr authored and steveicarus committed Nov 2, 2010
1 parent 77feb50 commit 225ca1e
Show file tree
Hide file tree
Showing 31 changed files with 167 additions and 190 deletions.
6 changes: 3 additions & 3 deletions HName.h
@@ -1,7 +1,7 @@
#ifndef __HName_H
#define __HName_H
/*
* Copyright (c) 2001-2008 Stephen Williams (steve@icarus.com)
* Copyright (c) 2001-2010 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
Expand Down Expand Up @@ -94,10 +94,10 @@ inline ostream& operator<< (ostream&out, const list<hname_t>&ll)
{
list<hname_t>::const_iterator cur = ll.begin();
out << *cur;
cur ++;
++ cur;
while (cur != ll.end()) {
out << "." << *cur;
cur ++;
++ cur;
}
return out;
}
Expand Down
2 changes: 1 addition & 1 deletion Makefile.in
Expand Up @@ -162,7 +162,7 @@ cppcheck: $(O:.o=.cc) $(srcdir)/dosify.c $(srcdir)/version.c
cppcheck-all:
$(foreach dir,$(SUBDIRS),$(MAKE) -C $(dir) cppcheck && ) true
$(foreach dir,$(NOTUSED),$(MAKE) -C $(dir) cppcheck && ) true
cppcheck
$(MAKE) cppcheck

Makefile: $(srcdir)/Makefile.in config.status
./config.status --file=$@
Expand Down
3 changes: 1 addition & 2 deletions Module.cc
Expand Up @@ -93,8 +93,7 @@ unsigned Module::find_port(const char*name) const
PGate* Module::get_gate(perm_string name)
{
for (list<PGate*>::iterator cur = gates_.begin()
; cur != gates_.end()
; cur ++ ) {
; cur != gates_.end() ; ++ cur ) {

if ((*cur)->get_name() == name)
return *cur;
Expand Down
14 changes: 7 additions & 7 deletions design_dump.cc
Expand Up @@ -1112,7 +1112,7 @@ void NetScope::dump(ostream&o) const
{
map<perm_string,param_expr_t>::const_iterator pp;
for (pp = parameters.begin()
; pp != parameters.end() ; pp ++) {
; pp != parameters.end() ; ++ pp ) {
o << " parameter ";

o << pp->second.type << " ";
Expand Down Expand Up @@ -1162,7 +1162,7 @@ void NetScope::dump(ostream&o) const
}

for (pp = localparams.begin()
; pp != localparams.end() ; pp ++) {
; pp != localparams.end() ; ++ pp ) {
o << " localparam " << (*pp).first << " = " <<
*(*pp).second.expr << ";" << endl;
}
Expand All @@ -1172,7 +1172,7 @@ void NetScope::dump(ostream&o) const
{
list<pair<pform_name_t,NetExpr*> >::const_iterator pp;
for (pp = defparams.begin()
; pp != defparams.end() ; pp ++ ) {
; pp != defparams.end() ; ++ pp ) {
o << " defparam " << (*pp).first << " = " <<
*(*pp).second << ";" << endl;
}
Expand All @@ -1181,7 +1181,7 @@ void NetScope::dump(ostream&o) const
{
list<pair<list<hname_t>,NetExpr*> >::const_iterator pp;
for (pp = defparams_later.begin()
; pp != defparams_later.end() ; pp ++ ) {
; pp != defparams_later.end() ; ++ pp ) {
o << " defparam(later) " << pp->first << " = " <<
*(pp->second) << ";" << endl;
}
Expand All @@ -1203,7 +1203,7 @@ void NetScope::dump(ostream&o) const
// Dump specparams
typedef map<perm_string,spec_val_t>::const_iterator specparam_it_t;
for (specparam_it_t cur = specparams.begin()
; cur != specparams.end() ; cur ++ ) {
; cur != specparams.end() ; ++ cur ) {
o << " specparam " << (*cur).first
<< " = ";
spec_val_t value = (*cur).second;
Expand Down Expand Up @@ -1240,7 +1240,7 @@ void NetScope::dump(ostream&o) const

/* Dump any sub-scopes. */
for (map<hname_t,NetScope*>::const_iterator cur = children_.begin()
; cur != children_.end() ; cur ++)
; cur != children_.end() ; ++ cur )
cur->second->dump(o);
}

Expand Down Expand Up @@ -1518,7 +1518,7 @@ void Design::dump(ostream&o) const
o << "DESIGN TIME PRECISION: 10e" << get_precision() << endl;
o << "SCOPES:" << endl;
for (list<NetScope*>::const_iterator scope = root_scopes_.begin();
scope != root_scopes_.end(); scope++)
scope != root_scopes_.end(); ++ scope )
(*scope)->dump(o);

o << "ELABORATED NODES:" << endl;
Expand Down
2 changes: 1 addition & 1 deletion elab_expr.cc
Expand Up @@ -1984,7 +1984,7 @@ static void probe_index_expr_width(Design*des, NetScope*scope,
const name_component_t&name)
{
for (list<index_component_t>::const_iterator cur = name.index.begin()
; cur != name.index.end() ; cur ++) {
; cur != name.index.end() ; ++ cur ) {

if (cur->msb)
probe_expr_width(des, scope, cur->msb);
Expand Down
44 changes: 22 additions & 22 deletions elab_scope.cc
Expand Up @@ -53,7 +53,7 @@ static void collect_scope_parameters_(NetScope*scope,
const map<perm_string,LexicalScope::param_expr_t>&parameters)
{
for (mparm_it_t cur = parameters.begin()
; cur != parameters.end() ; cur ++) {
; cur != parameters.end() ; ++ cur ) {

NetEParam*tmp = new NetEParam;
tmp->set_line(*((*cur).second.expr));
Expand All @@ -68,7 +68,7 @@ static void collect_scope_localparams_(NetScope*scope,
const map<perm_string,LexicalScope::param_expr_t>&localparams)
{
for (mparm_it_t cur = localparams.begin()
; cur != localparams.end() ; cur ++) {
; cur != localparams.end() ; ++ cur ) {

NetEParam*tmp = new NetEParam;
tmp->set_line(*((*cur).second.expr));
Expand Down Expand Up @@ -172,7 +172,7 @@ static void elaborate_scope_parameters_(Design*des, NetScope*scope,
const map<perm_string,LexicalScope::param_expr_t>&parameters)
{
for (mparm_it_t cur = parameters.begin()
; cur != parameters.end() ; cur ++) {
; cur != parameters.end() ; ++ cur ) {

// A parameter can not have the same name as a genvar.
if (scope->find_genvar((*cur).first)) {
Expand All @@ -191,7 +191,7 @@ static void elaborate_scope_localparams_(Design*des, NetScope*scope,
const map<perm_string,LexicalScope::param_expr_t>&localparams)
{
for (mparm_it_t cur = localparams.begin()
; cur != localparams.end() ; cur ++) {
; cur != localparams.end() ; ++ cur ) {

// A localparam can not have the same name as a genvar.
if (scope->find_genvar((*cur).first)) {
Expand All @@ -210,7 +210,7 @@ static void replace_scope_parameters_(NetScope*scope, const LineInfo&loc,
const Module::replace_t&replacements)
{
for (Module::replace_t::const_iterator cur = replacements.begin()
; cur != replacements.end() ; cur ++) {
; cur != replacements.end() ; ++ cur ) {

NetExpr*val = (*cur).second;
if (val == 0) {
Expand Down Expand Up @@ -240,7 +240,7 @@ static void elaborate_scope_events_(Design*des, NetScope*scope,
const map<perm_string,PEvent*>&events)
{
for (map<perm_string,PEvent*>::const_iterator et = events.begin()
; et != events.end() ; et ++ ) {
; et != events.end() ; ++ et ) {

(*et).second->elaborate_scope(des, scope);
}
Expand All @@ -253,7 +253,7 @@ static void elaborate_scope_tasks(Design*des, NetScope*scope,
typedef map<perm_string,PTask*>::const_iterator tasks_it_t;

for (tasks_it_t cur = tasks.begin()
; cur != tasks.end() ; cur ++ ) {
; cur != tasks.end() ; ++ cur ) {

hname_t use_name( (*cur).first );
// A task can not have the same name as another scope object.
Expand Down Expand Up @@ -308,7 +308,7 @@ static void elaborate_scope_funcs(Design*des, NetScope*scope,
typedef map<perm_string,PFunction*>::const_iterator funcs_it_t;

for (funcs_it_t cur = funcs.begin()
; cur != funcs.end() ; cur ++ ) {
; cur != funcs.end() ; ++ cur ) {

hname_t use_name( (*cur).first );
// A function can not have the same name as another scope object.
Expand Down Expand Up @@ -376,7 +376,7 @@ class generate_schemes_work_item_t : public elaborator_work_item_t {
// elaboration.
typedef list<PGenerate*>::const_iterator generate_it_t;
for (generate_it_t cur = mod_->generate_schemes.begin()
; cur != mod_->generate_schemes.end() ; cur ++ ) {
; cur != mod_->generate_schemes.end() ; ++ cur ) {
(*cur) -> generate_scope(des, scope_);
}
}
Expand All @@ -399,7 +399,7 @@ bool Module::elaborate_scope(Design*des, NetScope*scope,

// Add the genvars to the scope.
typedef map<perm_string,LineInfo*>::const_iterator genvar_it_t;
for (genvar_it_t cur = genvars.begin(); cur != genvars.end(); cur++ ) {
for (genvar_it_t cur = genvars.begin(); cur != genvars.end(); ++ cur ) {
scope->add_genvar((*cur).first, (*cur).second);
}

Expand Down Expand Up @@ -446,7 +446,7 @@ bool Module::elaborate_scope(Design*des, NetScope*scope,

typedef list<Module::named_expr_t>::const_iterator defparms_iter_t;
for (defparms_iter_t cur = defparms.begin()
; cur != defparms.end() ; cur ++) {
; cur != defparms.end() ; ++ cur ) {

PExpr*ex = cur->second;
assert(ex);
Expand Down Expand Up @@ -496,7 +496,7 @@ bool Module::elaborate_scope(Design*des, NetScope*scope,

typedef list<PGate*>::const_iterator gates_it_t;
for (gates_it_t cur = gates_.begin()
; cur != gates_.end() ; cur ++ ) {
; cur != gates_.end() ; ++ cur ) {

(*cur) -> elaborate_scope(des, scope);
}
Expand All @@ -509,7 +509,7 @@ bool Module::elaborate_scope(Design*des, NetScope*scope,
typedef list<PProcess*>::const_iterator proc_it_t;

for (proc_it_t cur = behaviors.begin()
; cur != behaviors.end() ; cur ++ ) {
; cur != behaviors.end() ; ++ cur ) {

(*cur) -> statement() -> elaborate_scope(des, scope);
}
Expand Down Expand Up @@ -849,7 +849,7 @@ bool PGenerate::generate_scope_case_(Design*des, NetScope*container)
// Detect that the item is a default.
if (item->item_test.size() == 0) {
default_item = item;
cur ++;
++ cur;
continue;
}

Expand Down Expand Up @@ -881,7 +881,7 @@ bool PGenerate::generate_scope_case_(Design*des, NetScope*container)
if (match_flag)
break;

cur ++;
++ cur;
}

delete case_value_co;
Expand Down Expand Up @@ -1017,7 +1017,7 @@ void PGenerate::elaborate_subscope_direct_(Design*des, NetScope*scope)
{
typedef list<PGenerate*>::const_iterator generate_it_t;
for (generate_it_t cur = generate_schemes.begin()
; cur != generate_schemes.end() ; cur ++ ) {
; cur != generate_schemes.end() ; ++ cur ) {
(*cur) -> generate_scope(des, scope);
}
}
Expand All @@ -1026,7 +1026,7 @@ void PGenerate::elaborate_subscope_(Design*des, NetScope*scope)
{
// Add the genvars to this scope.
typedef map<perm_string,LineInfo*>::const_iterator genvar_it_t;
for (genvar_it_t cur = genvars.begin(); cur != genvars.end(); cur++ ) {
for (genvar_it_t cur = genvars.begin(); cur != genvars.end(); ++ cur ) {
scope->add_genvar((*cur).first, (*cur).second);
}

Expand All @@ -1036,7 +1036,7 @@ void PGenerate::elaborate_subscope_(Design*des, NetScope*scope)

typedef list<PGenerate*>::const_iterator generate_it_t;
for (generate_it_t cur = generate_schemes.begin()
; cur != generate_schemes.end() ; cur ++ ) {
; cur != generate_schemes.end() ; ++ cur ) {
(*cur) -> generate_scope(des, scope);
}

Expand All @@ -1057,13 +1057,13 @@ void PGenerate::elaborate_subscope_(Design*des, NetScope*scope)
// their own scopes.
typedef list<PGate*>::const_iterator pgate_list_it_t;
for (pgate_list_it_t cur = gates.begin()
; cur != gates.end() ; cur ++) {
; cur != gates.end() ; ++ cur ) {
(*cur) ->elaborate_scope(des, scope);
}

typedef list<PProcess*>::const_iterator proc_it_t;
for (proc_it_t cur = behaviors.begin()
; cur != behaviors.end() ; cur ++ ) {
; cur != behaviors.end() ; ++ cur ) {
(*cur) -> statement() -> elaborate_scope(des, scope);
}

Expand Down Expand Up @@ -1331,7 +1331,7 @@ void PGModule::elaborate_scope_mod_instances_(Design*des, Module*mod, NetScope*s
replace[*cur] = (*overrides_)[jdx];

jdx += 1;
cur ++;
++ cur;
}
}

Expand All @@ -1352,7 +1352,7 @@ void PGModule::elaborate_scope_mod_instances_(Design*des, Module*mod, NetScope*s
// parameter value with the new expression.

for (mparm_local_it_t cur = replace.begin()
; cur != replace.end() ; cur ++ ) {
; cur != replace.end() ; ++ cur ) {

PExpr*tmp = (*cur).second;
// No expression means that the parameter is not
Expand Down

0 comments on commit 225ca1e

Please sign in to comment.