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
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<std::string> &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 <fcntl.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 */
@ -482,7 +482,7 @@ bool RsDirUtil::cleanupDirectory(std::string cleandir, std::list<std::string> 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 <iomanip>
/* 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) {

View File

@ -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<std::string> &subdirs);
int breakupDirList(const std::string& path, std::list<std::string> &subdirs);
bool checkDirectory(std::string dir);
bool checkCreateDirectory(std::string dir);
bool cleanupDirectory(std::string dir, std::list<std::string> keepFiles);
bool checkDirectory(const std::string& dir);
bool checkCreateDirectory(const std::string& dir);
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);
bool getFileHash(std::string filepath,
bool getFileHash(const std::string& filepath,
std::string &hash, uint64_t &size);