Skip to content

Commit ca70649

Browse files
committed
Fix review comments
Signed-off-by: Stephen Sun <[email protected]>
1 parent 3458442 commit ca70649

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

common/json.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,16 @@ bool JSon::loadJsonFromFile(ifstream &fs, vector<KeyOpFieldsValuesTuple> &db_ite
6363
return false;
6464
}
6565

66-
db_items.push_back(KeyOpFieldsValuesTuple());
67-
auto &cur_db_item = db_items[db_items.size() - 1];
66+
db_items.emplace_back(KeyOpFieldsValuesTuple());
67+
auto &cur_db_item = db_items.back();
6868

69-
for (nlohmann::json::iterator child_it = arr_item.begin(); child_it != arr_item.end(); child_it++) {
69+
for (auto child_it = arr_item.begin(); child_it != arr_item.end(); child_it++)
70+
{
7071
auto cur_obj_key = child_it.key();
7172
auto &cur_obj = child_it.value();
7273

73-
if (cur_obj.is_object()) {
74+
if (cur_obj.is_object())
75+
{
7476
kfvKey(cur_db_item) = cur_obj_key;
7577
for (nlohmann::json::iterator cur_obj_it = cur_obj.begin(); cur_obj_it != cur_obj.end(); cur_obj_it++)
7678
{
@@ -80,12 +82,13 @@ bool JSon::loadJsonFromFile(ifstream &fs, vector<KeyOpFieldsValuesTuple> &db_ite
8082
value_str = to_string((*cur_obj_it).get<int>());
8183
else if ((*cur_obj_it).is_string())
8284
value_str = (*cur_obj_it).get<string>();
83-
kfvFieldsValues(cur_db_item).push_back(FieldValueTuple(field_str, value_str));
85+
kfvFieldsValues(cur_db_item).emplace_back(FieldValueTuple(field_str, value_str));
8486
}
8587
}
8688
else
8789
{
8890
auto op = cur_obj.get<string>();
91+
8992
if (op != "SET")
9093
{
9194
SWSS_LOG_ERROR("Child elements'op field must be SET, but got %s, ignored", op.c_str());

0 commit comments

Comments
 (0)