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
This commit is contained in:
csoler 2010-10-01 20:05:09 +00:00
parent 978528824b
commit 6fc8f8831b
2 changed files with 24 additions and 25 deletions

View File

@ -56,7 +56,7 @@
****/ ****/
#define RSDIR_DEBUG 1 #define RSDIR_DEBUG 1
std::string RsDirUtil::getTopDir(std::string dir) std::string RsDirUtil::getTopDir(const std::string& dir)
{ {
std::string top; std::string top;
@ -225,7 +225,7 @@ hashing_failed:
return false ; return false ;
} }
std::string RsDirUtil::removeTopDir(std::string dir) std::string RsDirUtil::removeTopDir(const std::string& dir)
{ {
std::string rest; std::string rest;
@ -247,7 +247,7 @@ std::string RsDirUtil::removeTopDir(std::string dir)
return rest; return rest;
} }
std::string RsDirUtil::getRootDir(std::string dir) std::string RsDirUtil::getRootDir(const std::string& dir)
{ {
std::string root; std::string root;
@ -266,7 +266,7 @@ std::string RsDirUtil::getRootDir(std::string dir)
return root; return root;
} }
std::string RsDirUtil::removeRootDir(std::string path) std::string RsDirUtil::removeRootDir(const std::string& path)
{ {
unsigned int i, j; unsigned int i, j;
unsigned int len = path.length(); unsigned int len = path.length();
@ -288,7 +288,7 @@ std::string RsDirUtil::removeRootDir(std::string path)
return output; 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 */ /* too tired */
std::string notroot; 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<std::string> &subdirs) std::list<std::string> &subdirs)
{ {
int start = 0; 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; int val;
mode_t st_mode; 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 #ifdef RSDIR_DEBUG
std::cerr << "RsDirUtil::checkCreateDirectory() dir: " << dir << std::endl; std::cerr << "RsDirUtil::checkCreateDirectory() dir: " << dir << std::endl;
@ -440,7 +440,7 @@ bool RsDirUtil::checkCreateDirectory(std::string dir)
//#include <fcntl.h> //#include <fcntl.h>
//#include <unistd.h> //#include <unistd.h>
bool RsDirUtil::cleanupDirectory(std::string cleandir, std::list<std::string> keepFiles) bool RsDirUtil::cleanupDirectory(const std::string& cleandir, std::list<std::string> keepFiles)
{ {
/* check for the dir existance */ /* check for the dir existance */
@ -482,7 +482,7 @@ bool RsDirUtil::cleanupDirectory(std::string cleandir, std::list<std::string> k
} }
/* slightly nicer helper function */ /* 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) std::string &name, std::string &hash, uint64_t &size)
{ {
if (getFileHash(filepath, hash, size)) if (getFileHash(filepath, hash, size))
@ -500,7 +500,7 @@ bool RsDirUtil::hashFile(std::string filepath,
#include <iomanip> #include <iomanip>
/* Function to hash, and get details of a file */ /* 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) std::string &hash, uint64_t &size)
{ {
FILE *fd; FILE *fd;
@ -591,7 +591,7 @@ bool RsDirUtil::renameFile(const std::string& from, const std::string& to)
return true ; return true ;
} }
bool RsDirUtil::createBackup (std::string sFilename, unsigned int nCount) bool RsDirUtil::createBackup (const std::string& sFilename, unsigned int nCount)
{ {
#ifdef WINDOWS_SYS #ifdef WINDOWS_SYS
if (GetFileAttributesA (sFilename.c_str ()) == -1) { if (GetFileAttributesA (sFilename.c_str ()) == -1) {

View File

@ -36,18 +36,18 @@ class CRC32Map ;
namespace RsDirUtil { namespace RsDirUtil {
std::string getTopDir(std::string); std::string getTopDir(const std::string&);
std::string getRootDir(std::string); std::string getRootDir(const std::string&);
std::string removeRootDir(std::string path); std::string removeRootDir(const std::string& path);
std::string removeTopDir(std::string dir); std::string removeTopDir(const std::string& dir);
std::string removeRootDirs(std::string path, std::string root); std::string removeRootDirs(const std::string& path, const std::string& root);
bool hashFile(const std::string& full_path,std::string& hash) ; bool hashFile(const std::string& full_path,std::string& hash) ;
// Renames file from to file to. Files should be on the same file system. // Renames file from to file to. Files should be on the same file system.
// returns true if succeed, false otherwise. // returns true if succeed, false otherwise.
bool renameFile(const std::string& from,const std::string& to) ; 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 // 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) ; bool crc32File(FILE *f,uint64_t file_size,uint32_t chunk_size,CRC32Map& map) ;
int breakupDirList(std::string path, int breakupDirList(const std::string& path, std::list<std::string> &subdirs);
std::list<std::string> &subdirs);
bool checkDirectory(std::string dir); bool checkDirectory(const std::string& dir);
bool checkCreateDirectory(std::string dir); bool checkCreateDirectory(const std::string& dir);
bool cleanupDirectory(std::string dir, std::list<std::string> keepFiles); bool cleanupDirectory(const std::string& dir, std::list<std::string> keepFiles);
bool hashFile(std::string filepath, bool hashFile(const std::string& filepath,
std::string &name, std::string &hash, uint64_t &size); 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); std::string &hash, uint64_t &size);