aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Senozhatsky <sergey.senozhatsky@gmail.com>2011-05-06 19:40:52 +0300
committerArjan van de Ven <arjan@linux.intel.com>2011-05-11 00:04:24 -0400
commit40cdd6d7094fc1919c82f77d633410cef1604576 (patch)
tree634e4b60e9cf89dc0a2289db66a6daf0989c5320
parent0b13635f9a6824510a6f4bdadeecf06aef616281 (diff)
downloadpowertop-40cdd6d7094fc1919c82f77d633410cef1604576.tar.gz
lib: style: Pass const references of std::string
(Sorry, resend. Forget to fill the subject line properly). lib: Pass const references of std::string, avoiding temporary object creation. Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
-rw-r--r--lib.cpp7
-rw-r--r--lib.h6
2 files changed, 6 insertions, 7 deletions
diff --git a/lib.cpp b/lib.cpp
index 103c8ff..3c411c9 100644
--- a/lib.cpp
+++ b/lib.cpp
@@ -50,7 +50,6 @@ extern "C" {
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
-#include <string.h>
#include <locale.h>
#include <libintl.h>
#include <limits>
@@ -163,7 +162,7 @@ bool stringless::operator()(const char * const & lhs, const char * const & rhs)
return false;
}
-void write_sysfs(string filename, string value)
+void write_sysfs(const string &filename, const string &value)
{
ofstream file;
@@ -174,7 +173,7 @@ void write_sysfs(string filename, string value)
file.close();
}
-int read_sysfs(string filename)
+int read_sysfs(const string &filename)
{
ifstream file;
int i;
@@ -187,7 +186,7 @@ int read_sysfs(string filename)
return i;
}
-string read_sysfs_string(string filename)
+string read_sysfs_string(const string &filename)
{
ifstream file;
char content[4096];
diff --git a/lib.h b/lib.h
index f4e6889..2a7db5c 100644
--- a/lib.h
+++ b/lib.h
@@ -56,9 +56,9 @@ public:
#include <string>
using namespace std;
-extern void write_sysfs(string filename, string value);
-extern int read_sysfs(string filename);
-extern string read_sysfs_string(string filename);
+extern void write_sysfs(const string &filename, const string &value);
+extern int read_sysfs(const string &filename);
+extern string read_sysfs_string(const string &filename);
extern string read_sysfs_string(const char *format, const char *param);
extern void format_watts(double W, char *buffer, unsigned int len);