Skip to content

Commit 4ddecbb

Browse files
intorrXottab-DUTY
authored andcommitted
Simplify code. Use range-based for instead of iterators.
1 parent 10b6821 commit 4ddecbb

File tree

1 file changed

+26
-41
lines changed

1 file changed

+26
-41
lines changed

src/utils/xrCompress/xrCompress.cpp

Lines changed: 26 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ bool xrCompressor::testSKIP(LPCSTR path)
8888
if (0 == _stricmp(p_ext, ".rc"))
8989
return true;
9090

91-
for (xr_vector<shared_str>::iterator it = exclude_exts.begin(); it != exclude_exts.end(); ++it)
92-
if (PatternMatch(p_ext, it->c_str()))
91+
for (auto &it : exclude_exts)
92+
if (PatternMatch(p_ext, it.c_str()))
9393
return true;
9494

9595
return false;
@@ -352,15 +352,12 @@ void xrCompressor::OpenPack(LPCSTR tgt_folder, int num)
352352
{
353353
CMemoryWriter W;
354354
CInifile::Sect& S = config_ltx->r_section("header");
355-
auto it = S.Data.cbegin();
356-
auto it_e = S.Data.cend();
357355
string4096 buff;
358356
xr_sprintf(buff, "[%s]", S.Name.c_str());
359357
W.w_string(buff);
360-
for (; it != it_e; ++it)
358+
for (const auto &it : S.Data)
361359
{
362-
const CInifile::Item& I = *it;
363-
xr_sprintf(buff, "%s = %s", I.first.c_str(), I.second.c_str());
360+
xr_sprintf(buff, "%s = %s", it.first.c_str(), it.second.c_str());
364361
W.w_string(buff);
365362
}
366363
W.seek(0);
@@ -433,16 +430,15 @@ void xrCompressor::PerformWork()
433430
int pack_num = 0;
434431
OpenPack(target_name.c_str(), pack_num++);
435432

436-
for (u32 it = 0; it < folders_list->size(); it++)
437-
write_file_header((*folders_list)[it], 0, 0, 0, 0);
433+
for (auto &it : *folders_list)
434+
write_file_header(it, 0, 0, 0, 0);
438435

439436
if (!bStoreFiles)
440437
c_heap = xr_alloc<u8>(LZO1X_999_MEM_COMPRESS);
441438

442439
for (u32 it = 0; it < files_list->size(); it++)
443440
{
444-
xr_sprintf(
445-
caption, "Compress files: %d/%d - %d%%", it, files_list->size(), (it * 100) / files_list->size());
441+
xr_sprintf(caption, "Compress files: %d/%d - %d%%", it, files_list->size(), (it * 100) / files_list->size());
446442
SetWindowText(GetConsoleWindow(), caption);
447443
printf("\n%-80s ", (*files_list)[it]);
448444

@@ -481,17 +477,15 @@ void xrCompressor::ProcessTargetFolder()
481477

482478
void xrCompressor::GatherFiles(LPCSTR path)
483479
{
484-
xr_vector<char*>* i_list = FS.file_list_open("$target_folder$", path, FS_ListFiles | FS_RootOnly);
480+
auto i_list = FS.file_list_open("$target_folder$", path, FS_ListFiles | FS_RootOnly);
485481
if (!i_list)
486482
{
487483
Msg("ERROR: Unable to open file list:%s", path);
488484
return;
489485
}
490-
xr_vector<char*>::iterator it = i_list->begin();
491-
xr_vector<char*>::iterator itE = i_list->end();
492-
for (; it != itE; ++it)
486+
for (auto &it : *i_list)
493487
{
494-
xr_string tmp_path = xr_string(path) + xr_string(*it);
488+
xr_string tmp_path = xr_string(path) + xr_string(it);
495489
if (!testSKIP(tmp_path.c_str()))
496490
{
497491
files_list->push_back(xr_strdup(tmp_path.c_str()));
@@ -510,17 +504,17 @@ bool xrCompressor::IsFolderAccepted(CInifile& ltx, LPCSTR path, BOOL& recurse)
510504
if (ltx.section_exist("exclude_folders"))
511505
{
512506
CInifile::Sect& ef_sect = ltx.r_section("exclude_folders");
513-
for (auto ef_it = ef_sect.Data.cbegin(); ef_it != ef_sect.Data.cend(); ef_it++)
507+
for (auto &it : ef_sect.Data)
514508
{
515-
recurse = CInifile::isBool(ef_it->second.c_str());
509+
recurse = CInifile::isBool(it.second.c_str());
516510
if (recurse)
517511
{
518-
if (path == strstr(path, ef_it->first.c_str()))
512+
if (path == strstr(path, it.first.c_str()))
519513
return false;
520514
}
521515
else
522516
{
523-
if (0 == xr_strcmp(path, ef_it->first.c_str()))
517+
if (0 == xr_strcmp(path, it.first.c_str()))
524518
return false;
525519
}
526520
}
@@ -541,14 +535,13 @@ void xrCompressor::ProcessLTX(CInifile& ltx)
541535
if (ltx.section_exist("include_folders"))
542536
{
543537
CInifile::Sect& if_sect = ltx.r_section("include_folders");
544-
545-
for (auto if_it = if_sect.Data.cbegin(); if_it != if_sect.Data.cend(); ++if_it)
538+
for (auto &it : if_sect.Data)
546539
{
547-
BOOL ifRecurse = CInifile::isBool(if_it->second.c_str());
540+
BOOL ifRecurse = CInifile::isBool(it.second.c_str());
548541
u32 folder_mask = FS_ListFolders | (ifRecurse ? 0 : FS_RootOnly);
549542

550543
string_path path;
551-
LPCSTR _path = 0 == xr_strcmp(if_it->first.c_str(), ".\\") ? "" : if_it->first.c_str();
544+
LPCSTR _path = 0 == xr_strcmp(it.first.c_str(), ".\\") ? "" : it.first.c_str();
552545
xr_strcpy(path, _path);
553546
u32 path_len = xr_strlen(path);
554547
if ((0 != path_len) && (path[path_len - 1] != '\\'))
@@ -563,18 +556,16 @@ void xrCompressor::ProcessLTX(CInifile& ltx)
563556
if (val)
564557
GatherFiles(path);
565558

566-
xr_vector<char*>* i_fl_list = FS.file_list_open("$target_folder$", path, folder_mask);
559+
auto i_fl_list = FS.file_list_open("$target_folder$", path, folder_mask);
567560
if (!i_fl_list)
568561
{
569562
Msg("ERROR: Unable to open folder list:", path);
570563
continue;
571564
}
572565

573-
xr_vector<char*>::iterator it = i_fl_list->begin();
574-
xr_vector<char*>::iterator itE = i_fl_list->end();
575-
for (; it != itE; ++it)
566+
for (auto &it : *i_fl_list)
576567
{
577-
xr_string tmp_path = xr_string(path) + xr_string(*it);
568+
xr_string tmp_path = xr_string(path) + xr_string(it);
578569
bool val = IsFolderAccepted(ltx, tmp_path.c_str(), efRecurse);
579570
if (val)
580571
{
@@ -601,25 +592,19 @@ void xrCompressor::ProcessLTX(CInifile& ltx)
601592
if (ltx.section_exist("include_files"))
602593
{
603594
CInifile::Sect& if_sect = ltx.r_section("include_files");
604-
for (auto if_it = if_sect.Data.cbegin(); if_it != if_sect.Data.cend(); ++if_it)
605-
{
606-
files_list->push_back(xr_strdup(if_it->first.c_str()));
607-
}
595+
for (auto &it : if_sect.Data)
596+
files_list->push_back(xr_strdup(it.first.c_str()));
608597
}
609598

610599
PerformWork();
611600

612601
// free
613-
xr_vector<char*>::iterator it = files_list->begin();
614-
xr_vector<char*>::iterator itE = files_list->end();
615-
for (; it != itE; ++it)
616-
xr_free(*it);
602+
for (auto &it : *files_list)
603+
xr_free(it);
617604
xr_delete(files_list);
618605

619-
it = folders_list->begin();
620-
itE = folders_list->end();
621-
for (; it != itE; ++it)
622-
xr_free(*it);
606+
for (auto &it : *folders_list)
607+
xr_free(it);
623608
xr_delete(folders_list);
624609

625610
exclude_exts.clear_and_free();

0 commit comments

Comments
 (0)