Changeset - r25377:354616e8fc6a
[Not reviewed]
master
0 4 0
glx22 - 3 years ago 2021-04-29 23:13:50
glx@openttd.org
Codechange: Replace FOR_ALL_TARS with range-based for loops
4 files changed with 13 insertions and 18 deletions:
0 comments (0 inline, 0 general)
src/fileio.cpp
Show inline comments
 
@@ -1345,12 +1345,12 @@ static uint ScanPath(FileScanner *fs, co
 
 * @param extension the extension of files to search for.
 
 * @param tar       the tar to search in.
 
 */
 
static uint ScanTar(FileScanner *fs, const char *extension, TarFileList::iterator tar)
 
static uint ScanTar(FileScanner *fs, const char *extension, const TarFileList::value_type &tar)
 
{
 
	uint num = 0;
 
	const auto &filename = (*tar).first;
 
	const auto &filename = tar.first;
 

	
 
	if (MatchesExtension(extension, filename.c_str()) && fs->AddFile(filename, 0, (*tar).second.tar_filename)) num++;
 
	if (MatchesExtension(extension, filename.c_str()) && fs->AddFile(filename, 0, tar.second.tar_filename)) num++;
 

	
 
	return num;
 
}
 
@@ -1369,7 +1369,6 @@ uint FileScanner::Scan(const char *exten
 
	this->subdir = sd;
 

	
 
	Searchpath sp;
 
	TarFileList::iterator tar;
 
	uint num = 0;
 

	
 
	FOR_ALL_SEARCHPATHS(sp) {
 
@@ -1381,7 +1380,7 @@ uint FileScanner::Scan(const char *exten
 
	}
 

	
 
	if (tars && sd != NO_DIRECTORY) {
 
		FOR_ALL_TARS(tar, sd) {
 
		for (const auto &tar : _tar_filelist[sd]) {
 
			num += ScanTar(this, extension, tar);
 
		}
 
	}
src/game/game_text.cpp
Show inline comments
 
@@ -249,16 +249,15 @@ GameStrings *LoadTranslations()
 
		if (!tar_filename.empty() && (iter = _tar_list[GAME_DIR].find(tar_filename)) != _tar_list[GAME_DIR].end()) {
 
			/* The main script is in a tar file, so find all files that
 
			 * are in the same tar and add them to the langfile scanner. */
 
			TarFileList::iterator tar;
 
			FOR_ALL_TARS(tar, GAME_DIR) {
 
			for (const auto &tar : _tar_filelist[GAME_DIR]) {
 
				/* Not in the same tar. */
 
				if (tar->second.tar_filename != iter->first) continue;
 
				if (tar.second.tar_filename != iter->first) continue;
 

	
 
				/* Check the path and extension. */
 
				if (tar->first.size() <= ldir.size() || tar->first.compare(0, ldir.size(), ldir) != 0) continue;
 
				if (tar->first.compare(tar->first.size() - 4, 4, ".txt") != 0) continue;
 
				if (tar.first.size() <= ldir.size() || tar.first.compare(0, ldir.size(), ldir) != 0) continue;
 
				if (tar.first.compare(tar.first.size() - 4, 4, ".txt") != 0) continue;
 

	
 
				scanner.AddFile(tar->first, 0, tar_filename);
 
				scanner.AddFile(tar.first, 0, tar_filename);
 
			}
 
		} else {
 
			/* Scan filesystem */
src/script/script_scanner.cpp
Show inline comments
 
@@ -224,16 +224,15 @@ static bool IsSameScript(const ContentIn
 
	if (!tar_filename.empty() && (iter = _tar_list[dir].find(tar_filename)) != _tar_list[dir].end()) {
 
		/* The main script is in a tar file, so find all files that
 
		 * are in the same tar and add them to the MD5 checksumming. */
 
		TarFileList::iterator tar;
 
		FOR_ALL_TARS(tar, dir) {
 
		for (const auto &tar : _tar_filelist[dir]) {
 
			/* Not in the same tar. */
 
			if (tar->second.tar_filename != iter->first) continue;
 
			if (tar.second.tar_filename != iter->first) continue;
 

	
 
			/* Check the extension. */
 
			const char *ext = strrchr(tar->first.c_str(), '.');
 
			const char *ext = strrchr(tar.first.c_str(), '.');
 
			if (ext == nullptr || strcasecmp(ext, ".nut") != 0) continue;
 

	
 
			checksum.AddFile(tar->first, 0, tar_filename);
 
			checksum.AddFile(tar.first, 0, tar_filename);
 
		}
 
	} else {
 
		char path[MAX_PATH];
src/tar_type.h
Show inline comments
 
@@ -28,6 +28,4 @@ typedef std::map<std::string, TarFileLis
 
extern std::array<TarList, NUM_SUBDIRS> _tar_list;
 
extern TarFileList _tar_filelist[NUM_SUBDIRS];
 

	
 
#define FOR_ALL_TARS(tar, sd) for (tar = _tar_filelist[sd].begin(); tar != _tar_filelist[sd].end(); tar++)
 

	
 
#endif /* TAR_TYPE_H */
0 comments (0 inline, 0 general)