diff options
| author | isanae <14251494+isanae@users.noreply.github.com> | 2020-12-24 10:55:55 -0500 |
|---|---|---|
| committer | isanae <14251494+isanae@users.noreply.github.com> | 2020-12-24 10:55:55 -0500 |
| commit | 5183b2f47ad240174bf653b299af9e068a3b83e4 (patch) | |
| tree | b611c98fe9c6b89975acc2313676ce8a14ac673f /src/envfs.cpp | |
| parent | c8cff6166d05e77c843bb727702607f970d3d030 (diff) | |
optimizations for download manager:
- use envfs for walking directory
- minimize string copies, disk access
- use set of filenames to check for duplicates
- use file size from envfs
Diffstat (limited to 'src/envfs.cpp')
| -rw-r--r-- | src/envfs.cpp | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/envfs.cpp b/src/envfs.cpp index 20ba4229..9317eb70 100644 --- a/src/envfs.cpp +++ b/src/envfs.cpp @@ -298,14 +298,17 @@ void forEachEntryImpl( ObjectName.MaximumLength = ObjectName.Length; if (DirInfo->FileAttributes & FILE_ATTRIBUTE_DIRECTORY) { - dirStartF(cx, toStringView(&oa)); - forEachEntryImpl(cx, hc, buffers, &oa, depth+1, dirStartF, dirEndF, fileF); - dirEndF(cx, toStringView(&oa)); + if (dirStartF && dirEndF) { + dirStartF(cx, toStringView(&oa)); + forEachEntryImpl(cx, hc, buffers, &oa, depth+1, dirStartF, dirEndF, fileF); + dirEndF(cx, toStringView(&oa)); + } } else { FILETIME ft; ft.dwLowDateTime = DirInfo->LastWriteTime.LowPart; ft.dwHighDateTime = DirInfo->LastWriteTime.HighPart; - fileF(cx, toStringView(&oa), ft); + + fileF(cx, toStringView(&oa), ft, DirInfo->AllocationSize.QuadPart); } } @@ -380,20 +383,20 @@ Directory getFilesAndDirs(const std::wstring& path) cx->current.pop(); }, - [](void* pcx, std::wstring_view path, FILETIME ft) { + [](void* pcx, std::wstring_view path, FILETIME ft, uint64_t s) { Context* cx = (Context*)pcx; - cx->current.top()->files.push_back(File(path, ft)); + cx->current.top()->files.push_back(File(path, ft, s)); } ); return root; } -File::File(std::wstring_view n, FILETIME ft) : +File::File(std::wstring_view n, FILETIME ft, uint64_t s) : name(n.begin(), n.end()), lcname(MOShared::ToLowerCopy(name)), - lastModified(ft) + lastModified(ft), size(s) { } @@ -429,7 +432,11 @@ void getFilesAndDirsWithFindImpl(const std::wstring& path, Directory& d) getFilesAndDirsWithFindImpl(newPath, d.dirs.back()); } } else { - d.files.push_back(File(findData.cFileName, findData.ftLastWriteTime)); + const auto size = + (findData.nFileSizeHigh * (MAXDWORD+1)) + findData.nFileSizeLow; + + d.files.push_back(File( + findData.cFileName, findData.ftLastWriteTime, size)); } result = ::FindNextFileW(searchHandle, &findData); |
