From 6fc8f8831be91484a8983ee3eb1724f1fa2cf1ab Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 1 Oct 2010 20:05:09 +0000 Subject: [PATCH] put some consts& around std::string in rsdir to improve performance git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3581 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/util/rsdir.cc | 24 ++++++++++++------------ libretroshare/src/util/rsdir.h | 25 ++++++++++++------------- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/libretroshare/src/util/rsdir.cc b/libretroshare/src/util/rsdir.cc index cdd6d9e56..a11d90421 100644 --- a/libretroshare/src/util/rsdir.cc +++ b/libretroshare/src/util/rsdir.cc @@ -56,7 +56,7 @@ ****/ #define RSDIR_DEBUG 1 -std::string RsDirUtil::getTopDir(std::string dir) +std::string RsDirUtil::getTopDir(const std::string& dir) { std::string top; @@ -225,7 +225,7 @@ hashing_failed: return false ; } -std::string RsDirUtil::removeTopDir(std::string dir) +std::string RsDirUtil::removeTopDir(const std::string& dir) { std::string rest; @@ -247,7 +247,7 @@ std::string RsDirUtil::removeTopDir(std::string dir) return rest; } -std::string RsDirUtil::getRootDir(std::string dir) +std::string RsDirUtil::getRootDir(const std::string& dir) { std::string root; @@ -266,7 +266,7 @@ std::string RsDirUtil::getRootDir(std::string dir) return root; } -std::string RsDirUtil::removeRootDir(std::string path) +std::string RsDirUtil::removeRootDir(const std::string& path) { unsigned int i, j; unsigned int len = path.length(); @@ -288,7 +288,7 @@ std::string RsDirUtil::removeRootDir(std::string path) return output; } -std::string RsDirUtil::removeRootDirs(std::string path, std::string root) +std::string RsDirUtil::removeRootDirs(const std::string& path, const std::string& root) { /* too tired */ std::string notroot; @@ -335,7 +335,7 @@ std::string RsDirUtil::removeRootDirs(std::string path, std::string root) -int RsDirUtil::breakupDirList(std::string path, +int RsDirUtil::breakupDirList(const std::string& path, std::list &subdirs) { int start = 0; @@ -361,7 +361,7 @@ int RsDirUtil::breakupDirList(std::string path, -bool RsDirUtil::checkDirectory(std::string dir) +bool RsDirUtil::checkDirectory(const std::string& dir) { int val; mode_t st_mode; @@ -397,7 +397,7 @@ bool RsDirUtil::checkDirectory(std::string dir) } -bool RsDirUtil::checkCreateDirectory(std::string dir) +bool RsDirUtil::checkCreateDirectory(const std::string& dir) { #ifdef RSDIR_DEBUG std::cerr << "RsDirUtil::checkCreateDirectory() dir: " << dir << std::endl; @@ -440,7 +440,7 @@ bool RsDirUtil::checkCreateDirectory(std::string dir) //#include //#include -bool RsDirUtil::cleanupDirectory(std::string cleandir, std::list keepFiles) +bool RsDirUtil::cleanupDirectory(const std::string& cleandir, std::list keepFiles) { /* check for the dir existance */ @@ -482,7 +482,7 @@ bool RsDirUtil::cleanupDirectory(std::string cleandir, std::list k } /* slightly nicer helper function */ -bool RsDirUtil::hashFile(std::string filepath, +bool RsDirUtil::hashFile(const std::string& filepath, std::string &name, std::string &hash, uint64_t &size) { if (getFileHash(filepath, hash, size)) @@ -500,7 +500,7 @@ bool RsDirUtil::hashFile(std::string filepath, #include /* Function to hash, and get details of a file */ -bool RsDirUtil::getFileHash(std::string filepath, +bool RsDirUtil::getFileHash(const std::string& filepath, std::string &hash, uint64_t &size) { FILE *fd; @@ -591,7 +591,7 @@ bool RsDirUtil::renameFile(const std::string& from, const std::string& to) return true ; } -bool RsDirUtil::createBackup (std::string sFilename, unsigned int nCount) +bool RsDirUtil::createBackup (const std::string& sFilename, unsigned int nCount) { #ifdef WINDOWS_SYS if (GetFileAttributesA (sFilename.c_str ()) == -1) { diff --git a/libretroshare/src/util/rsdir.h b/libretroshare/src/util/rsdir.h index 4069f7519..6455e4eaa 100644 --- a/libretroshare/src/util/rsdir.h +++ b/libretroshare/src/util/rsdir.h @@ -36,18 +36,18 @@ class CRC32Map ; namespace RsDirUtil { -std::string getTopDir(std::string); -std::string getRootDir(std::string); -std::string removeRootDir(std::string path); -std::string removeTopDir(std::string dir); -std::string removeRootDirs(std::string path, std::string root); +std::string getTopDir(const std::string&); +std::string getRootDir(const std::string&); +std::string removeRootDir(const std::string& path); +std::string removeTopDir(const std::string& dir); +std::string removeRootDirs(const std::string& path, const std::string& root); bool hashFile(const std::string& full_path,std::string& hash) ; // Renames file from to file to. Files should be on the same file system. // returns true if succeed, false otherwise. bool renameFile(const std::string& from,const std::string& to) ; -bool createBackup (std::string sFilename, unsigned int nCount = 5); +bool createBackup (const std::string& sFilename, unsigned int nCount = 5); // returns the CRC32 of the data of length len // @@ -57,17 +57,16 @@ uint32_t rs_CRC32(const unsigned char *data,uint32_t len) ; // bool crc32File(FILE *f,uint64_t file_size,uint32_t chunk_size,CRC32Map& map) ; -int breakupDirList(std::string path, - std::list &subdirs); +int breakupDirList(const std::string& path, std::list &subdirs); -bool checkDirectory(std::string dir); -bool checkCreateDirectory(std::string dir); -bool cleanupDirectory(std::string dir, std::list keepFiles); +bool checkDirectory(const std::string& dir); +bool checkCreateDirectory(const std::string& dir); +bool cleanupDirectory(const std::string& dir, std::list keepFiles); -bool hashFile(std::string filepath, +bool hashFile(const std::string& filepath, std::string &name, std::string &hash, uint64_t &size); -bool getFileHash(std::string filepath, +bool getFileHash(const std::string& filepath, std::string &hash, uint64_t &size);