Make functions in fileutils.h use "const std::string&".

This way, the strings are not copied everytime the function is called.

BUG=webrtc:7142
NOTRY=True

Review-Url: https://codereview.webrtc.org/2685583009
Cr-Commit-Position: refs/heads/master@{#16537}
This commit is contained in:
ehmaldonado 2017-02-10 09:27:14 -08:00 committed by Commit bot
parent 46a0021e4e
commit 88df0bc591
2 changed files with 10 additions and 8 deletions

View File

@ -101,7 +101,7 @@ void SetExecutablePath(const std::string& path) {
relative_dir_path_set = true;
}
bool FileExists(std::string& file_name) {
bool FileExists(const std::string& file_name) {
struct stat file_info = {0};
return stat(file_name.c_str(), &file_info) == 0;
}
@ -206,7 +206,7 @@ std::string TempFilename(const std::string &dir, const std::string &prefix) {
#endif
}
bool CreateDir(std::string directory_name) {
bool CreateDir(const std::string& directory_name) {
struct stat path_info = {0};
// Check if the path exists already:
if (stat(directory_name.c_str(), &path_info) == 0) {
@ -226,7 +226,8 @@ bool CreateDir(std::string directory_name) {
return true;
}
std::string ResourcePath(std::string name, std::string extension) {
std::string ResourcePath(const std::string& name,
const std::string& extension) {
#if defined(WEBRTC_IOS)
return IOSResourcePath(name, extension);
#else
@ -270,7 +271,7 @@ std::string ResourcePath(std::string name, std::string extension) {
#endif // defined (WEBRTC_IOS)
}
size_t GetFileSize(std::string filename) {
size_t GetFileSize(const std::string& filename) {
FILE* f = fopen(filename.c_str(), "rb");
size_t size = 0;
if (f != NULL) {

View File

@ -58,7 +58,8 @@ std::string TempFilename(const std::string &dir, const std::string &prefix);
// If a directory path is prepended to the filename, a subdirectory
// hierarchy reflecting that path is assumed to be present.
// extension - File extension, without the dot, i.e. "bmp" or "yuv".
std::string ResourcePath(std::string name, std::string extension);
std::string ResourcePath(const std::string& name,
const std::string& extension);
// Gets the current working directory for the executing program.
// Returns "./" if for some reason it is not possible to find the working
@ -68,14 +69,14 @@ std::string WorkingDir();
// Creates a directory if it not already exists.
// Returns true if successful. Will print an error message to stderr and return
// false if a file with the same name already exists.
bool CreateDir(std::string directory_name);
bool CreateDir(const std::string& directory_name);
// Checks if a file exists.
bool FileExists(std::string& file_name);
bool FileExists(const std::string& file_name);
// File size of the supplied file in bytes. Will return 0 if the file is
// empty or if the file does not exist/is readable.
size_t GetFileSize(std::string filename);
size_t GetFileSize(const std::string& filename);
// Sets the executable path, i.e. the path to the executable that is being used
// when launching it. This is usually the path relative to the working directory