mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-26 01:31:30 -05:00
reduced CPU cost of file index by suppressing lots of std::string copy actions
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3917 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
254e3de187
commit
8cfe5abbe2
@ -686,6 +686,8 @@ void FileIndexMonitor::updateCycle()
|
||||
{
|
||||
#ifdef FIM_DEBUG
|
||||
std::cerr << "File ModTime/Size changed:" << fname << std::endl;
|
||||
std::cerr << "fe.modtime = " << fe.modtime << std::endl;
|
||||
std::cerr << "fit.mdtime = " << fit->second->modtime << std::endl;
|
||||
#endif
|
||||
toadd = true;
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ int DirEntry::updateChildRows()
|
||||
}
|
||||
|
||||
|
||||
int DirEntry::removeDir(std::string name)
|
||||
int DirEntry::removeDir(const std::string& name)
|
||||
{
|
||||
/* if it doesn't exist - add */
|
||||
std::map<std::string, DirEntry *>::iterator it;
|
||||
@ -174,7 +174,7 @@ int DirEntry::removeDir(std::string name)
|
||||
}
|
||||
|
||||
|
||||
int DirEntry::removeFile(std::string name)
|
||||
int DirEntry::removeFile(const std::string& name)
|
||||
{
|
||||
/* if it doesn't exist - add */
|
||||
std::map<std::string, FileEntry *>::iterator it;
|
||||
@ -206,7 +206,7 @@ int DirEntry::removeFile(std::string name)
|
||||
|
||||
|
||||
|
||||
int DirEntry::removeOldDir(std::string name, time_t old)
|
||||
int DirEntry::removeOldDir(const std::string& name, time_t old)
|
||||
{
|
||||
std::map<std::string, DirEntry *>::iterator it;
|
||||
DirEntry *ndir = NULL;
|
||||
@ -329,7 +329,7 @@ DirEntry *DirEntry::findOldDirectory(time_t old)
|
||||
}
|
||||
|
||||
|
||||
DirEntry *DirEntry::findDirectory(std::string fpath)
|
||||
DirEntry *DirEntry::findDirectory(const std::string& fpath)
|
||||
{
|
||||
std::string nextdir = RsDirUtil::getRootDir(fpath);
|
||||
std::map<std::string, DirEntry *>::iterator it;
|
||||
@ -353,7 +353,7 @@ DirEntry *DirEntry::findDirectory(std::string fpath)
|
||||
}
|
||||
|
||||
|
||||
int DirEntry::updateDirectories(std::string fpath, int new_pop, int new_modtime)
|
||||
int DirEntry::updateDirectories(const std::string& fpath, int new_pop, int new_modtime)
|
||||
{
|
||||
int ret = 1;
|
||||
if (path != "") /* if not there -> continue down tree */
|
||||
@ -384,7 +384,7 @@ int DirEntry::updateDirectories(std::string fpath, int new_pop, int new_modtime)
|
||||
return ret;
|
||||
}
|
||||
|
||||
DirEntry *DirEntry::updateDir(FileEntry fe, time_t utime)
|
||||
DirEntry *DirEntry::updateDir(const FileEntry& fe, time_t utime)
|
||||
{
|
||||
/* if it doesn't exist - add */
|
||||
std::map<std::string, DirEntry *>::iterator it;
|
||||
@ -424,7 +424,7 @@ DirEntry *DirEntry::updateDir(FileEntry fe, time_t utime)
|
||||
}
|
||||
|
||||
|
||||
FileEntry *DirEntry::updateFile(FileEntry fe, time_t utime)
|
||||
FileEntry *DirEntry::updateFile(const FileEntry& fe, time_t utime)
|
||||
{
|
||||
/* if it doesn't exist - add */
|
||||
std::map<std::string, FileEntry *>::iterator it;
|
||||
@ -517,7 +517,7 @@ int DirEntry::print(std::ostream &out)
|
||||
return 1;
|
||||
}
|
||||
|
||||
FileIndex::FileIndex(std::string pid)
|
||||
FileIndex::FileIndex(const std::string& pid)
|
||||
{
|
||||
root = new PersonEntry(pid);
|
||||
registerEntry(root) ;
|
||||
@ -592,7 +592,7 @@ int FileIndex::getRootDirectories(std::list<std::string> &outlist)
|
||||
}
|
||||
|
||||
/* update (index building) */
|
||||
DirEntry *FileIndex::updateDirEntry(std::string fpath, FileEntry fe, time_t utime)
|
||||
DirEntry *FileIndex::updateDirEntry(const std::string& fpath, const FileEntry& fe, time_t utime)
|
||||
{
|
||||
/* path is to parent */
|
||||
#ifdef FI_DEBUG_ALL
|
||||
@ -621,7 +621,7 @@ DirEntry *FileIndex::updateDirEntry(std::string fpath, FileEntry fe, time_t utim
|
||||
}
|
||||
|
||||
|
||||
FileEntry *FileIndex::updateFileEntry(std::string fpath, FileEntry fe, time_t utime)
|
||||
FileEntry *FileIndex::updateFileEntry(const std::string& fpath, const FileEntry& fe, time_t utime)
|
||||
{
|
||||
/* path is to parent */
|
||||
#ifdef FI_DEBUG_ALL
|
||||
@ -662,7 +662,7 @@ DirEntry *FileIndex::findOldDirectory(time_t old) /* finds directories older t
|
||||
return olddir;
|
||||
}
|
||||
|
||||
int FileIndex::removeOldDirectory(std::string fpath, std::string name, time_t old)
|
||||
int FileIndex::removeOldDirectory(const std::string& fpath, const std::string& name, time_t old)
|
||||
{
|
||||
/* path is to parent */
|
||||
#ifdef FI_DEBUG_ALL
|
||||
@ -716,7 +716,7 @@ int FileIndex::printFileIndex(std::ostream &out)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int FileIndex::loadIndex(std::string filename, std::string expectedHash, uint64_t size)
|
||||
int FileIndex::loadIndex(const std::string& filename, const std::string& expectedHash, uint64_t size)
|
||||
{
|
||||
std::ifstream file (filename.c_str(), std::ifstream::binary);
|
||||
if (!file)
|
||||
@ -918,7 +918,7 @@ error:
|
||||
}
|
||||
|
||||
|
||||
int FileIndex::saveIndex(std::string filename, std::string &fileHash, uint64_t &size,const std::set<std::string>& forbidden_dirs)
|
||||
int FileIndex::saveIndex(const std::string& filename, std::string &fileHash, uint64_t &size,const std::set<std::string>& forbidden_dirs)
|
||||
{
|
||||
unsigned char sha_buf[SHA_DIGEST_LENGTH];
|
||||
std::string filenametmp = filename + ".tmp" ;
|
||||
@ -1008,9 +1008,10 @@ int FileIndex::saveIndex(std::string filename, std::string &fileHash, uint64_t &
|
||||
}
|
||||
|
||||
|
||||
std::string FixName(std::string in)
|
||||
std::string FixName(const std::string& _in)
|
||||
{
|
||||
/* replace any , with _ */
|
||||
std::string in(_in) ;
|
||||
for(unsigned int i = 0; i < in.length(); i++)
|
||||
{
|
||||
if (in[i] == FILE_CACHE_SEPARATOR_CHAR)
|
||||
@ -1068,7 +1069,7 @@ int DirEntry::saveEntry(std::ostringstream &oss)
|
||||
}
|
||||
|
||||
|
||||
int FileIndex::searchHash(std::string hash, std::list<FileEntry *> &results) const
|
||||
int FileIndex::searchHash(const std::string& hash, std::list<FileEntry *> &results) const
|
||||
{
|
||||
#ifdef FI_DEBUG
|
||||
std::cerr << "FileIndex::searchHash(" << hash << ")";
|
||||
@ -1109,7 +1110,7 @@ int FileIndex::searchHash(std::string hash, std::list<FileEntry *> &results) con
|
||||
}
|
||||
|
||||
|
||||
int FileIndex::searchTerms(std::list<std::string> terms, std::list<FileEntry *> &results) const
|
||||
int FileIndex::searchTerms(const std::list<std::string>& terms, std::list<FileEntry *> &results) const
|
||||
{
|
||||
DirEntry *ndir = NULL;
|
||||
std::list<DirEntry *> dirlist;
|
||||
|
@ -114,27 +114,27 @@ class DirEntry: public FileEntry
|
||||
virtual ~DirEntry();
|
||||
|
||||
/* update local entries */
|
||||
DirEntry * updateDir(FileEntry fe, time_t updtime);
|
||||
FileEntry * updateFile(FileEntry fe, time_t updtime);
|
||||
DirEntry * updateDir(const FileEntry& fe, time_t updtime);
|
||||
FileEntry * updateFile(const FileEntry& fe, time_t updtime);
|
||||
|
||||
|
||||
int checkParentPointers();
|
||||
int updateChildRows();
|
||||
|
||||
/* remove local entries */
|
||||
int removeFile(std::string name);
|
||||
int removeDir(std::string name);
|
||||
int removeOldDir(std::string name, time_t old); /* checks ts first */
|
||||
int removeFile(const std::string& name);
|
||||
int removeDir(const std::string& name);
|
||||
int removeOldDir(const std::string& name, time_t old); /* checks ts first */
|
||||
|
||||
/* recursive cleanup */
|
||||
int removeOldEntries(time_t old, bool recursive);
|
||||
|
||||
/* recursive searches */
|
||||
DirEntry * findOldDirectory(time_t old);
|
||||
DirEntry * findDirectory(std::string path);
|
||||
DirEntry * findDirectory(const std::string& path);
|
||||
|
||||
/* recursive update directory mod/pop values */
|
||||
int updateDirectories(std::string path, int pop, int modtime);
|
||||
int updateDirectories(const std::string& path, int pop, int modtime);
|
||||
|
||||
/* output */
|
||||
int print(std::ostream &out);
|
||||
@ -170,7 +170,7 @@ class PersonEntry: public DirEntry
|
||||
{
|
||||
public:
|
||||
/* cleanup */
|
||||
PersonEntry(std::string pid) : id(pid) { return; }
|
||||
PersonEntry(const std::string& pid) : id(pid) { return; }
|
||||
virtual ~PersonEntry() { return; }
|
||||
|
||||
DirEntry &operator=(DirEntry &src)
|
||||
@ -204,7 +204,7 @@ class Expression;
|
||||
class FileIndex
|
||||
{
|
||||
public:
|
||||
FileIndex(std::string pid);
|
||||
FileIndex(const std::string& pid);
|
||||
~FileIndex();
|
||||
|
||||
/* control root entries */
|
||||
@ -212,11 +212,11 @@ class FileIndex
|
||||
int getRootDirectories(std::list<std::string> &outlist);
|
||||
|
||||
/* update (index building) */
|
||||
DirEntry * updateDirEntry(std::string path, FileEntry fe, time_t utime);
|
||||
FileEntry * updateFileEntry(std::string path, FileEntry fe, time_t utime);
|
||||
DirEntry * updateDirEntry(const std::string& path, const FileEntry& fe, time_t utime);
|
||||
FileEntry * updateFileEntry(const std::string& path, const FileEntry& fe, time_t utime);
|
||||
|
||||
DirEntry * findOldDirectory(time_t old); /* finds directories older than old */
|
||||
int removeOldDirectory(std::string fpath, std::string name, time_t old);
|
||||
int removeOldDirectory(const std::string& fpath, const std::string& name, time_t old);
|
||||
|
||||
int cleanOldEntries(time_t old); /* removes entries older than old */
|
||||
|
||||
@ -224,12 +224,12 @@ class FileIndex
|
||||
int printFileIndex(std::ostream &out);
|
||||
|
||||
/* load/save to file */
|
||||
int loadIndex(std::string filename, std::string expectedHash, uint64_t size);
|
||||
int saveIndex(std::string filename, std::string &fileHash, uint64_t &size, const std::set<std::string>& forbidden_roots);
|
||||
int loadIndex(const std::string& filename, const std::string& expectedHash, uint64_t size);
|
||||
int saveIndex(const std::string& filename, std::string &fileHash, uint64_t &size, const std::set<std::string>& forbidden_roots);
|
||||
|
||||
/* search through this index */
|
||||
int searchTerms(std::list<std::string> terms, std::list<FileEntry *> &results) const;
|
||||
int searchHash(std::string hash, std::list<FileEntry *> &results) const;
|
||||
int searchTerms(const std::list<std::string>& terms, std::list<FileEntry *> &results) const;
|
||||
int searchHash(const std::string& hash, std::list<FileEntry *> &results) const;
|
||||
int searchBoolExp(Expression * exp, std::list<FileEntry *> &results) const;
|
||||
|
||||
/// Recursively compute the maximum modification time of children.
|
||||
|
Loading…
x
Reference in New Issue
Block a user