Author: alink
Date: Thu Jun 12 00:25:25 2008
New Revision: 27107
URL: http://svn.gna.org/viewcvs/wesnoth?rev=27107&view=rev
Log:
Small optimization of the cache validation phase:
find files and check changes in the same pass.
Modified:
trunk/src/filesystem.cpp
trunk/src/filesystem.hpp
Modified: trunk/src/filesystem.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/filesystem.cpp?rev=27107&r1=27106&r2=27107&view=diff
==============================================================================
--- trunk/src/filesystem.cpp (original)
+++ trunk/src/filesystem.cpp Thu Jun 12 00:25:25 2008
@@ -91,7 +91,8 @@
std::vector<std::string>* dirs,
FILE_NAME_MODE mode,
FILE_FILTER filter,
- FILE_REORDER_OPTION reorder)
+ FILE_REORDER_OPTION reorder,
+ file_tree_checksum* checksum)
{
// If we have a path to find directories in,
// then convert relative pathnames to be rooted
@@ -100,7 +101,7 @@
if(!directory.empty() && directory[0] != '/' &&
!game_config::path.empty()){
const std::string& dir = game_config::path + "/" + directory;
if(is_directory(dir)) {
- get_files_in_dir(dir,files,dirs,mode,filter,reorder);
+
get_files_in_dir(dir,files,dirs,mode,filter,reorder,checksum);
return;
}
}
@@ -181,6 +182,13 @@
else
files->push_back(basename);
}
+ if (checksum != NULL) {
+ if(st.st_mtime > checksum->modified) {
+ checksum->modified =
st.st_mtime;
+ }
+ checksum->sum_size += st.st_size;
+ checksum->nfiles++;
+ }
} else if (S_ISDIR(st.st_mode)) {
if (filter == SKIP_MEDIA_DIR
&& (basename == "images"||
basename == "sounds"))
@@ -696,21 +704,10 @@
static void get_file_tree_checksum_internal(const std::string& path,
file_tree_checksum& res)
{
- std::vector<std::string> files, dirs;
- get_files_in_dir(path,&files,&dirs, ENTIRE_FILE_PATH, SKIP_MEDIA_DIR);
+
+ std::vector<std::string> dirs;
+ get_files_in_dir(path,NULL,&dirs, ENTIRE_FILE_PATH, SKIP_MEDIA_DIR,
DONT_REORDER, &res);
increment_filesystem_progress();
- for(std::vector<std::string>::const_iterator i = files.begin(); i !=
files.end(); ++i) {
- ++res.nfiles;
-
- struct stat buf;
- if(::stat(i->c_str(),&buf) != -1) {
- if(buf.st_mtime > res.modified) {
- res.modified = buf.st_mtime;
- }
-
- res.sum_size += buf.st_size;
- }
- }
for(std::vector<std::string>::const_iterator j = dirs.begin(); j !=
dirs.end(); ++j) {
get_file_tree_checksum_internal(*j,res);
Modified: trunk/src/filesystem.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/filesystem.hpp?rev=27107&r1=27106&r2=27107&view=diff
==============================================================================
--- trunk/src/filesystem.hpp (original)
+++ trunk/src/filesystem.hpp Thu Jun 12 00:25:25 2008
@@ -35,6 +35,8 @@
std::string message;
};
+struct file_tree_checksum;
+
enum FILE_NAME_MODE { ENTIRE_FILE_PATH, FILE_NAME_ONLY };
enum FILE_FILTER { NO_FILTER, SKIP_MEDIA_DIR};
enum FILE_REORDER_OPTION { DONT_REORDER, DO_REORDER };
@@ -43,13 +45,17 @@
//! 'dirs' with all the directories in dir.
//! If files or dirs are NULL they will not be used.
//!
-//! Mode determines whether the entire path or just the filename is retrieved.
+//! mode: determines whether the entire path or just the filename is retrieved.
+//! filter: determines if we skip images and sounds directories
+//! reorder: triggers the special handling of _main.cfg and _final.cfg
+//! checksum: can be used to store checksum info
void get_files_in_dir(const std::string dir,
std::vector<std::string>* files,
std::vector<std::string>* dirs=NULL,
FILE_NAME_MODE mode=FILE_NAME_ONLY,
- FILE_FILTER = NO_FILTER,
- FILE_REORDER_OPTION reorder=DONT_REORDER);
+ FILE_FILTER filter = NO_FILTER,
+ FILE_REORDER_OPTION reorder=DONT_REORDER,
+ file_tree_checksum* checksum = NULL);
std::string get_dir(const std::string &dir);
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits