Skip to content

Commit

Permalink
Per #1019, for SonarQube replace ALL instances of push_back() with em…
Browse files Browse the repository at this point in the history
…place_back() which SonarQube prefers for efficiency.
  • Loading branch information
JohnHalleyGotway committed Jan 14, 2025
1 parent d04d83e commit c02f1c9
Show file tree
Hide file tree
Showing 69 changed files with 392 additions and 392 deletions.
22 changes: 11 additions & 11 deletions internal/test_util/libcode/vx_nc_util/test_pressure_levels.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ int main(int argc, char *argv[]) {
map<string, vector<string> > variable_levels;

vector<string> u_levels;
u_levels.push_back("P1000");
u_levels.push_back("P800");
u_levels.push_back("P500");
u_levels.emplace_back("P1000");
u_levels.emplace_back("P800");
u_levels.emplace_back("P500");
variable_levels["U"] = u_levels;

vector<string> v_levels;
v_levels.push_back("P1000");
v_levels.push_back("P900");
v_levels.push_back("P700");
v_levels.push_back("P500");
v_levels.push_back("P300");
v_levels.push_back("P100");
v_levels.push_back("P50");
v_levels.push_back("P10");
v_levels.emplace_back("P1000");
v_levels.emplace_back("P900");
v_levels.emplace_back("P700");
v_levels.emplace_back("P500");
v_levels.emplace_back("P300");
v_levels.emplace_back("P100");
v_levels.emplace_back("P50");
v_levels.emplace_back("P10");
variable_levels["V"] = v_levels;

for (map<string, vector<string> >::iterator i = variable_levels.begin();
Expand Down
2 changes: 1 addition & 1 deletion src/basic/vx_config/config_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ vector<MaskLatLon> parse_conf_llpnt_mask(Dictionary *dict) {
}

// Add current MaskLatLon to the vector
v.push_back(m);
v.emplace_back(m);
}

return v;
Expand Down
2 changes: 1 addition & 1 deletion src/basic/vx_config/threshold.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ void Simple_Node::get_simple_nodes(vector<Simple_Node> &v) const

{

v.push_back(*this);
v.emplace_back(*this);

return;

Expand Down
12 changes: 6 additions & 6 deletions src/basic/vx_log/string_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ void StringArray::add(const std::string text)

{

s.push_back(text);
s.emplace_back(text);

Sorted = false;

Expand All @@ -277,7 +277,7 @@ void StringArray::add_uniq(const std::string text)

if(!has(text)) {

s.push_back(text);
s.emplace_back(text);

Sorted = false;

Expand Down Expand Up @@ -323,7 +323,7 @@ for(int i=0; i<a.n(); i++) {

if(!has(a[i])) {

s.push_back(a[i]);
s.emplace_back(a[i]);

Sorted = false;

Expand Down Expand Up @@ -378,7 +378,7 @@ void StringArray::set(const std::string text)

s.clear();

s.push_back(text);
s.emplace_back(text);

// Setting to a single value, by nature it is Sorted
Sorted = true;
Expand Down Expand Up @@ -625,12 +625,12 @@ void StringArray::parse_delim(const std::string text, const char *delim)
size_t end = str.find_first_of(delim);
while (end != string::npos) {
if (start != end)
s.push_back(str.substr(start, end-start).c_str());
s.emplace_back(str.substr(start, end-start).c_str());
start = end + 1;
end = str.find_first_of(delim, start);
}
if (start < str.length())
s.push_back(str.substr(start).c_str());
s.emplace_back(str.substr(start).c_str());

Sorted = false;

Expand Down
8 changes: 4 additions & 4 deletions src/basic/vx_math/pwl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ Name = NAME;

for (int j=0; j<Npoints; ++j) {

X.push_back(XX[j]);
Y.push_back(YY[j]);
X.emplace_back(XX[j]);
Y.emplace_back(YY[j]);

}

Expand Down Expand Up @@ -266,8 +266,8 @@ void PiecewiseLinear::add_point(double xx, double yy)

{

X.push_back(xx);
Y.push_back(yy);
X.emplace_back(xx);
Y.emplace_back(yy);

return;

Expand Down
12 changes: 6 additions & 6 deletions src/basic/vx_util/GridTemplate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ GridTemplate::GridTemplate(const GridTemplate& rhs) {

for (offset_iter = rhs._offsetList.begin();
offset_iter != rhs._offsetList.end(); ++offset_iter)
_offsetList.push_back(new GridOffset(*offset_iter));
_offsetList.emplace_back(new GridOffset(*offset_iter));

_pointInGridBase = rhs._pointInGridBase;
_pointInGridNumX = rhs._pointInGridNumX;
Expand Down Expand Up @@ -506,7 +506,7 @@ void GridTemplate::printOffsetList(FILE *stream) {
void GridTemplate::_addOffset(int x_offset, int y_offset) {
GridOffset *offset = new GridOffset(x_offset, y_offset);

_offsetList.push_back(offset);
_offsetList.emplace_back(offset);

return;
}
Expand Down Expand Up @@ -558,28 +558,28 @@ void GridTemplate::_setEdgeOffsets() {
for(m_iterator = min_x_by_y.begin();
m_iterator != min_x_by_y.end();
m_iterator++) {
_offsetLftEdge.push_back(m_iterator->second);
_offsetLftEdge.emplace_back(m_iterator->second);
}

// Store max_x_by_y map as _offsetRgtEdge vector
for(m_iterator = max_x_by_y.begin();
m_iterator != max_x_by_y.end();
m_iterator++) {
_offsetRgtEdge.push_back(m_iterator->second);
_offsetRgtEdge.emplace_back(m_iterator->second);
}

// Store max_y_by_x map as _offsetTopEdge vector
for(m_iterator = max_y_by_x.begin();
m_iterator != max_y_by_x.end();
m_iterator++) {
_offsetTopEdge.push_back(m_iterator->second);
_offsetTopEdge.emplace_back(m_iterator->second);
}

// Store min_y_by_x map as _offsetBotEdge vector
for(m_iterator = min_y_by_x.begin();
m_iterator != min_y_by_x.end();
m_iterator++) {
_offsetBotEdge.push_back(m_iterator->second);
_offsetBotEdge.emplace_back(m_iterator->second);
}

return;
Expand Down
4 changes: 2 additions & 2 deletions src/basic/vx_util/GridTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ class GridTemplate {
// Access methods

inline void addOffset(const GridOffset &offset) {
_offsetList.push_back(new GridOffset(offset.x_offset,
_offsetList.emplace_back(new GridOffset(offset.x_offset,
offset.y_offset));
}

inline void addOffset(const int x_offset, const int y_offset) {
_offsetList.push_back(new GridOffset(x_offset, y_offset));
_offsetList.emplace_back(new GridOffset(x_offset, y_offset));
}

int size(void) const {
Expand Down
2 changes: 1 addition & 1 deletion src/basic/vx_util/ascii_header.cc
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ void AsciiHeader::read(const char *version) {
header_line.set_col_names(line[3]);

// Store the current line
Headers.push_back(header_line);
Headers.emplace_back(header_line);
}

// Store the version we just loaded
Expand Down
4 changes: 2 additions & 2 deletions src/basic/vx_util/crc_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ void CRC_Array<T>::add(const T & k)

extend(Nelements + 1, false);

e.push_back(k);
e.emplace_back(k);

Nelements++;

Expand All @@ -494,7 +494,7 @@ int j;

for (j=0; j<(a.Nelements); ++j) {

e.push_back(a.e[j]);
e.emplace_back(a.e[j]);

Nelements++;

Expand Down
10 changes: 5 additions & 5 deletions src/basic/vx_util/data_line.cc
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ size_t len, tpos = std::string::npos;

if (0 == Line.find_first_not_of(Delimiter)) { // no leading delimiter
++count;
Items.push_back(Line.substr(pos, Line.find_first_of(Delimiter, pos) - pos));
Items.emplace_back(Line.substr(pos, Line.find_first_of(Delimiter, pos) - pos));
}
while ((tpos = Line.substr(pos).find_first_of(Delimiter)) != std::string::npos) {
len = Line.substr(pos+tpos).find_first_not_of(Delimiter);
Expand All @@ -357,7 +357,7 @@ while ((tpos = Line.substr(pos).find_first_of(Delimiter)) != std::string::npos)
pos += tpos + len;

++count;
Items.push_back(Line.substr(pos, Line.find_first_of(Delimiter, pos) - pos));
Items.emplace_back(Line.substr(pos, Line.find_first_of(Delimiter, pos) - pos));
}

N_items = count;
Expand Down Expand Up @@ -408,15 +408,15 @@ sregex_token_iterator end;
//

while (it != end) {
Items.push_back(*it);
Items.emplace_back(*it);
++it;
}

//
// Append empty item if string ends with a delimiter
//

if ( Delimiter.find(Line.back()) != string::npos ) Items.push_back("");
if ( Delimiter.find(Line.back()) != string::npos ) Items.emplace_back("");

N_items = Items.size();

Expand Down Expand Up @@ -504,7 +504,7 @@ for( i=0; i<n_wdth; i++ ) {
}
}

Items.push_back(Line.substr(start, pos-start));
Items.emplace_back(Line.substr(start, pos-start));

//
// null terminate the entry
Expand Down
8 changes: 4 additions & 4 deletions src/basic/vx_util/num_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ void NumArray::add(double d)

{

e.push_back(d);
e.emplace_back(d);

Sorted = false;

Expand All @@ -375,7 +375,7 @@ void NumArray::add(const NumArray & a)

for (j=0; j<(a.n_elements()); ++j) {

e.push_back(a.e[j]);
e.emplace_back(a.e[j]);

}

Expand All @@ -399,7 +399,7 @@ void NumArray::add_const(double v, int n)

for (j=0; j<n; ++j) {

e.push_back(v);
e.emplace_back(v);

}

Expand All @@ -423,7 +423,7 @@ void NumArray::add_seq(int beg, int end)

for (j=beg; j<=end; ++j) {

e.push_back(j);
e.emplace_back(j);

}

Expand Down
2 changes: 1 addition & 1 deletion src/libcode/vx_bool_calc/bool_calc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ for (size_t j=0; j<P.size(); ++j) {
if (tok.type == tok_local_var) {
int index = tok.number_1b - 1;
if (find(args.begin(), args.end(), index) == args.end()) {
args.push_back(index);
args.emplace_back(index);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/libcode/vx_bool_calc/make_program.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ while ( op.nonempty() ) {

}

program.push_back(tok);
program.emplace_back(tok);

}

Expand Down Expand Up @@ -157,7 +157,7 @@ if ( t.is_mark() ) { op.push(t); return; }
//////////////////////////////////////


if ( t.is_operand() ) { program.push_back(t); return; }
if ( t.is_operand() ) { program.emplace_back(t); return; }


//////////////////////////////////////
Expand All @@ -177,7 +177,7 @@ if ( t.is_operator() ) {

tt = op.pop();

program.push_back(tt);
program.emplace_back(tt);

} // while

Expand Down Expand Up @@ -211,7 +211,7 @@ if ( t.is_unmark() ) {
tt = op.pop();

if ( tt.is_mark() ) { mark_found = true; break; }
else program.push_back(tt);
else program.emplace_back(tt);

}

Expand Down
2 changes: 1 addition & 1 deletion src/libcode/vx_data2d/data_class.cc
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ for(int i=0; i<vi_list.size(); i++) {
// Store the result
//

dp_list.push_back(cur_dp);
dp_list.emplace_back(cur_dp);

}

Expand Down
Loading

0 comments on commit c02f1c9

Please sign in to comment.