Use standard constructor to copy std::list to std::vector

There are a few places in the code where a std::list is copied to a
std::vector by iterating through the list and copying each element over to
the vector. The std::vector type has a iterator based constructor that can
do the same.

Update the code to use it instead. This removes a bit of boilerplate code
and also makes it easier to update the code.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2023-01-06 18:56:24 -08:00
parent ce243268d0
commit e7f66fe7ac
6 changed files with 22 additions and 98 deletions

View File

@ -99,14 +99,8 @@ PEAssignPattern::PEAssignPattern()
}
PEAssignPattern::PEAssignPattern(const list<PExpr*>&p)
: parms_(p.size())
: parms_(p.begin(), p.end())
{
size_t idx = 0;
for (list<PExpr*>::const_iterator cur = p.begin()
; cur != p.end() ; ++cur) {
parms_[idx] = *cur;
idx += 1;
}
}
PEAssignPattern::~PEAssignPattern()
@ -239,14 +233,9 @@ static pform_name_t pn_from_ps(perm_string n)
return tmp;
}
PECallFunction::PECallFunction(PPackage*pkg, const pform_name_t &n, const list<PExpr *> &parms)
: path_(pkg, n), parms_(parms.size()), is_overridden_(false)
PECallFunction::PECallFunction(PPackage*pkg, const pform_name_t&n, const list<PExpr *> &parms)
: path_(pkg, n), parms_(parms.begin(), parms.end()), is_overridden_(false)
{
int tmp_idx = 0;
ivl_assert(*this, parms_.size() == parms.size());
for (list<PExpr*>::const_iterator idx = parms.begin()
; idx != parms.end() ; ++idx)
parms_[tmp_idx++] = *idx;
}
PECallFunction::PECallFunction(perm_string n, const vector<PExpr*>&parms)
@ -261,23 +250,13 @@ PECallFunction::PECallFunction(perm_string n)
// NOTE: Anachronism. Try to work all use of svector out.
PECallFunction::PECallFunction(const pform_name_t&n, const list<PExpr *> &parms)
: path_(n), parms_(parms.size()), is_overridden_(false)
: path_(n), parms_(parms.begin(), parms.end()), is_overridden_(false)
{
int tmp_idx = 0;
ivl_assert(*this, parms_.size() == parms.size());
for (list<PExpr*>::const_iterator idx = parms.begin()
; idx != parms.end() ; ++idx)
parms_[tmp_idx++] = *idx;
}
PECallFunction::PECallFunction(perm_string n, const list<PExpr*>&parms)
: path_(pn_from_ps(n)), parms_(parms.size()), is_overridden_(false)
: package_(0), path_(pn_from_ps(n)), parms_(parms.begin(), parms.end()), is_overridden_(false)
{
int tmp_idx = 0;
ivl_assert(*this, parms_.size() == parms.size());
for (list<PExpr*>::const_iterator idx = parms.begin()
; idx != parms.end() ; ++idx)
parms_[tmp_idx++] = *idx;
}
PECallFunction::~PECallFunction()
@ -303,14 +282,8 @@ bool PECallFunction::has_aa_term(Design*des, NetScope*scope) const
}
PEConcat::PEConcat(const list<PExpr*>&p, PExpr*r)
: parms_(p.size()), width_modes_(SIZED, p.size()), repeat_(r)
: parms_(p.begin(), p.end()), width_modes_(SIZED, p.size()), repeat_(r)
{
int tmp_idx = 0;
ivl_assert(*this, parms_.size() == p.size());
for (list<PExpr*>::const_iterator idx = p.begin()
; idx != p.end() ; ++idx)
parms_[tmp_idx++] = *idx;
tested_scope_ = 0;
repeat_count_ = 1;
}
@ -494,13 +467,8 @@ PENewClass::PENewClass(void)
}
PENewClass::PENewClass(const list<PExpr*>&p, data_type_t *class_type)
: parms_(p.size()), class_type_(class_type)
: parms_(p.begin(), p.end()), class_type_(class_type)
{
size_t tmp_idx = 0;
for (list<PExpr*>::const_iterator cur = p.begin()
; cur != p.end() ; ++ cur) {
parms_[tmp_idx++] = *cur;
}
}
PENewClass::~PENewClass()

View File

@ -19,10 +19,11 @@
# include "PSpec.h"
PSpecPath::PSpecPath(unsigned src_cnt, unsigned dst_cnt, char polarity,
bool full_flag)
PSpecPath::PSpecPath(const std::list<perm_string> &src_list,
const std::list<perm_string> &dst_list,
char polarity, bool full_flag)
: conditional(false), condition(0), edge(0),
src(src_cnt), dst(dst_cnt),
src(src_list.begin(), src_list.end()), dst(dst_list.begin(), dst_list.end()),
data_source_expression(0)
{
full_flag_ = full_flag;

View File

@ -22,6 +22,7 @@
# include "LineInfo.h"
# include "StringHeap.h"
# include <vector>
# include <list>
class PExpr;
@ -56,8 +57,9 @@ class PExpr;
class PSpecPath : public LineInfo {
public:
PSpecPath(unsigned src_cnt, unsigned dst_cnt, char polarity,
bool full_flag);
PSpecPath(const std::list<perm_string> &src_list,
const std::list<perm_string> &dst_list,
char polarity, bool full_flag);
~PSpecPath();
void elaborate(class Design*des, class NetScope*scope) const;

View File

@ -167,36 +167,18 @@ PNamedItem::SymbolType PBlock::symbol_type() const
}
PCallTask::PCallTask(const pform_name_t&n, const list<PExpr*>&p)
: package_(0), path_(n), parms_(p.size())
: package_(0), path_(n), parms_(p.begin(), p.end())
{
list<PExpr*>::const_iterator cur = p.begin();
for (size_t idx = 0 ; idx < parms_.size() ; idx += 1) {
parms_[idx] = *cur;
++cur;
}
ivl_assert(*this, cur == p.end());
}
PCallTask::PCallTask(PPackage*pkg, const pform_name_t&n, const list<PExpr*>&p)
: package_(pkg), path_(n), parms_(p.size())
: package_(pkg), path_(n), parms_(p.begin(), p.end())
{
list<PExpr*>::const_iterator cur = p.begin();
for (size_t idx = 0 ; idx < parms_.size() ; idx += 1) {
parms_[idx] = *cur;
++cur;
}
ivl_assert(*this, cur == p.end());
}
PCallTask::PCallTask(perm_string n, const list<PExpr*>&p)
: package_(0), parms_(p.size())
: package_(0), parms_(p.begin(), p.end())
{
list<PExpr*>::const_iterator cur = p.begin();
for (size_t idx = 0 ; idx < parms_.size() ; idx += 1) {
parms_[idx] = *cur;
++cur;
}
ivl_assert(*this, cur == p.end());
path_.push_back(name_component_t(n));
}
@ -235,14 +217,8 @@ PCAssign::~PCAssign()
}
PChainConstructor::PChainConstructor(const list<PExpr*>&parms)
: parms_(parms.size())
: parms_(parms.begin(), parms.end())
{
list<PExpr*>::const_iterator cur = parms.begin();
for (size_t idx = 0 ; idx < parms_.size() ; idx += 1) {
parms_[idx] = *cur;
++cur;
}
ivl_assert(*this, cur == parms.end());
}
PChainConstructor::~PChainConstructor()
@ -350,12 +326,8 @@ PForce::~PForce()
}
PForeach::PForeach(perm_string av, const list<perm_string>&ix, Statement*s)
: array_var_(av), index_vars_(ix.size()), statement_(s)
: array_var_(av), index_vars_(ix.begin(), ix.end()), statement_(s)
{
size_t idx = 0;
for (list<perm_string>::const_iterator cur = ix.begin()
; cur != ix.end() ; ++cur)
index_vars_[idx++] = *cur;
}
PForeach::~PForeach()

View File

@ -579,16 +579,10 @@ NetNet::NetNet(NetScope*s, perm_string n, Type t,
: NetObj(s, n, calculate_count(unpacked)),
type_(t), port_type_(NOT_A_PORT),
local_flag_(false), net_type_(use_net_type),
discipline_(0), unpacked_dims_(unpacked.size()),
discipline_(0), unpacked_dims_(unpacked.begin(), unpacked.end()),
eref_count_(0), lref_count_(0)
{
calculate_slice_widths_from_packed_dims_();
size_t idx = 0;
for (list<netrange_t>::const_iterator cur = unpacked.begin()
; cur != unpacked.end() ; ++cur, idx += 1) {
unpacked_dims_[idx] = *cur;
}
ivl_assert(*this, idx == unpacked_dims_.size());
ivl_assert(*this, s);
if (pin_count() == 0) {

View File

@ -3053,23 +3053,10 @@ extern PSpecPath* pform_make_specify_path(const struct vlltype&li,
list<perm_string>*src, char pol,
bool full_flag, list<perm_string>*dst)
{
PSpecPath*path = new PSpecPath(src->size(), dst->size(), pol, full_flag);
PSpecPath*path = new PSpecPath(*src, *dst, pol, full_flag);
FILE_NAME(path, li);
unsigned idx;
list<perm_string>::const_iterator cur;
idx = 0;
for (idx = 0, cur = src->begin() ; cur != src->end() ; ++ idx, ++ cur) {
path->src[idx] = *cur;
}
ivl_assert(li, idx == path->src.size());
delete src;
for (idx = 0, cur = dst->begin() ; cur != dst->end() ; ++ idx, ++ cur) {
path->dst[idx] = *cur;
}
ivl_assert(li, idx == path->dst.size());
delete dst;
return path;