clang-tidy: Enable modernize-use-emplace check
The check flags insertions to an STL-style container done by
calling the push_back, push, or push_front methods with an
explicitly-constructed temporary of the container element type.
In this case, the corresponding emplace equivalent methods result
in less verbose and potentially more efficient code.
Change-Id: I1e7ae19ef1400c83717b2df48f3314ba4e96423e
Signed-off-by: Pavithra Barithaya <pavithrabarithaya07@gmail.com>
diff --git a/.clang-tidy b/.clang-tidy
index cba7e92..b816a4e 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -217,6 +217,7 @@
modernize-unary-static-assert,
modernize-use-bool-literals,
modernize-use-default-member-init,
+modernize-use-emplace,
modernize-use-equals-default,
modernize-use-equals-delete,
modernize-use-noexcept,
diff --git a/systemd_target_parser.cpp b/systemd_target_parser.cpp
index fe51d1a..9482c65 100644
--- a/systemd_target_parser.cpp
+++ b/systemd_target_parser.cpp
@@ -31,9 +31,9 @@
}
// delete "default" and insert defaults
errorsToMonitor.erase(errorItr);
- errorsToMonitor.push_back("timeout");
- errorsToMonitor.push_back("failed");
- errorsToMonitor.push_back("dependency");
+ errorsToMonitor.emplace_back("timeout");
+ errorsToMonitor.emplace_back("failed");
+ errorsToMonitor.emplace_back("dependency");
}
}
diff --git a/test/systemd_parser.cpp b/test/systemd_parser.cpp
index 7277f60..65fbec4 100644
--- a/test/systemd_parser.cpp
+++ b/test/systemd_parser.cpp
@@ -49,8 +49,8 @@
std::fclose(tmpf);
std::vector<std::string> filePaths;
- filePaths.push_back("/tmp/good_file1.json");
- filePaths.push_back("/tmp/good_file2.json");
+ filePaths.emplace_back("/tmp/good_file1.json");
+ filePaths.emplace_back("/tmp/good_file2.json");
TargetErrorData targetData = parseFiles(filePaths);
@@ -89,7 +89,7 @@
std::fclose(tmpf);
std::vector<std::string> filePaths;
- filePaths.push_back("/tmp/invalid_error_file.json");
+ filePaths.emplace_back("/tmp/invalid_error_file.json");
// Verify exception thrown on invalid errorsToMonitor
EXPECT_THROW(TargetErrorData targetData = parseFiles(filePaths),
@@ -104,7 +104,7 @@
fclose(tmpf);
std::vector<std::string> filePaths;
- filePaths.push_back("/tmp/invalid_json_file.json");
+ filePaths.emplace_back("/tmp/invalid_json_file.json");
// Verify exception thrown on invalid json file format
EXPECT_THROW(TargetErrorData targetData = parseFiles(filePaths),
@@ -129,7 +129,7 @@
std::fclose(tmpf);
std::vector<std::string> filePaths;
- filePaths.push_back("/tmp/not_just_default_file.json");
+ filePaths.emplace_back("/tmp/not_just_default_file.json");
// Verify exception thrown on invalid errorsToMonitor
EXPECT_THROW(TargetErrorData targetData = parseFiles(filePaths),