OSDN Git Service

Fix clang-tidy warnings in iotop.
authorChih-Hung Hsieh <chh@google.com>
Tue, 2 Aug 2016 18:19:23 +0000 (11:19 -0700)
committerChih-Hung Hsieh <chh@google.com>
Tue, 2 Aug 2016 18:19:23 +0000 (11:19 -0700)
* Declare explicit conversion constructors.
* Use const reference type for parameter to avoid unnecessary copy.

Bug: 28341362
Bug: 30407689
Change-Id: Ia95a041125703ecbfac128709fd6ea0591df2103
Test: build with WITH_TIDY=1

iotop/iotop.cpp
iotop/tasklist.cpp
iotop/taskstats.h

index 828fb32..e2582e8 100644 (file)
@@ -53,7 +53,7 @@ static void usage(char* myname) {
 }
 
 using Sorter = std::function<void(std::vector<TaskStatistics>&)>;
-static Sorter GetSorter(const std::string field) {
+static Sorter GetSorter(const std::string& field) {
   // Generic comparator
   static auto comparator = [](auto& lhs, auto& rhs, auto field, bool ascending) -> bool {
     auto a = (lhs.*field)();
index f81143f..0708741 100644 (file)
@@ -28,7 +28,7 @@
 #include "tasklist.h"
 
 template<typename Func>
-static bool ScanPidsInDir(std::string name, Func f) {
+static bool ScanPidsInDir(const std::string& name, Func f) {
   std::unique_ptr<DIR, decltype(&closedir)> dir(opendir(name.c_str()), closedir);
   if (!dir) {
     return false;
index f5ad2d2..bbf7e9e 100644 (file)
@@ -25,7 +25,7 @@ struct taskstats;
 
 class TaskStatistics {
 public:
-  TaskStatistics(const taskstats&);
+  explicit TaskStatistics(const taskstats&);
   TaskStatistics() = default;
   TaskStatistics(const TaskStatistics&) = default;
   void AddPidToTgid(const TaskStatistics&);