diff options
| author | ezbyDev <198480541+ezbyDev@users.noreply.github.com> | 2026-11-22 23:40:31 +0100 |
|---|---|---|
| committer | ezbyDev <198480541+ezbyDev@users.noreply.github.com> | 2026-11-22 23:40:31 +0100 |
| commit | 8518626c1b4925ad93bd852d58faa50c1a86e7cc (patch) | |
| tree | d535a1074fda6eef648e1195dc0be831b23a1a61 /runtime/shims/file_system.cpp | |
| parent | 08fc8ec748e35bc79985cf040310a7898b5d694c (diff) | |
file_system: list a GAME: folder in linear time (RT-257)
collect() probed the overlay for a deletion marker twice per package entry
(two is_regular_file calls), also when the folder has no marker folder at
all, and de-duplicated names by comparing each one with every name kept so
far. Listing 16,000 package files took 3.7 s against 9 ms on the host.
Every marker for an entry of the listed folder lives inside that folder's
marker folder, so probe it once and skip the per-entry checks when it is
missing. Keep the names seen in an unordered_set, folded with _wcslwr_s,
which follows the same locale rule as the _wcsicmp that same_name uses.
Tests: names that differ only in case are one entry with the overlay's
spelling, and a 300-file folder without a marker folder lists every file.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/shims/file_system.cpp')
| -rw-r--r-- | runtime/shims/file_system.cpp | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/runtime/shims/file_system.cpp b/runtime/shims/file_system.cpp index a965bfb0a..17a0c689f 100644 --- a/runtime/shims/file_system.cpp +++ b/runtime/shims/file_system.cpp | |||
| @@ -32,6 +32,7 @@ | |||
| 32 | #include <memory> | 32 | #include <memory> |
| 33 | #include <mutex> | 33 | #include <mutex> |
| 34 | #include <string> | 34 | #include <string> |
| 35 | #include <unordered_set> | ||
| 35 | #include <vector> | 36 | #include <vector> |
| 36 | 37 | ||
| 37 | #include "file_system.h" | 38 | #include "file_system.h" |
| @@ -479,6 +480,19 @@ bool collect(const std::wstring& pattern, const std::vector<std::wstring>& parts | |||
| 479 | return false; | 480 | return false; |
| 480 | } | 481 | } |
| 481 | 482 | ||
| 483 | // Every deletion marker for an entry of this folder lives inside its marker folder, so when that folder is missing | ||
| 484 | // nothing here is deleted and the per-entry probes (two file checks each) can be skipped. | ||
| 485 | std::error_code ec; | ||
| 486 | const bool has_markers = !r.overlay.empty() && std::filesystem::is_directory(marker(r.overlay, dirs), ec); | ||
| 487 | // Names already listed, folded the way same_name (_wcsicmp) compares them: _wcslwr_s uses the same locale rule. | ||
| 488 | std::unordered_set<std::wstring> seen; | ||
| 489 | auto key = [](const wchar_t* name) { | ||
| 490 | std::wstring k = name; | ||
| 491 | _wcslwr_s(k.data(), k.size() + 1); | ||
| 492 | return k; | ||
| 493 | }; | ||
| 494 | for (const auto& e : out) seen.insert(key(e.cFileName)); | ||
| 495 | |||
| 482 | auto add_root = [&](const std::filesystem::path& root, bool overlay_root) { | 496 | auto add_root = [&](const std::filesystem::path& root, bool overlay_root) { |
| 483 | if (root.empty()) return; | 497 | if (root.empty()) return; |
| 484 | std::filesystem::path search = join(root, dirs); | 498 | std::filesystem::path search = join(root, dirs); |
| @@ -489,18 +503,12 @@ bool collect(const std::wstring& pattern, const std::vector<std::wstring>& parts | |||
| 489 | do { | 503 | do { |
| 490 | if (overlay_root && internal_dir(found.cFileName)) continue; | 504 | if (overlay_root && internal_dir(found.cFileName)) continue; |
| 491 | const bool dot = same_name(found.cFileName, L".") || same_name(found.cFileName, L".."); | 505 | const bool dot = same_name(found.cFileName, L".") || same_name(found.cFileName, L".."); |
| 492 | if (!overlay_root && !dot) { | 506 | if (!overlay_root && !dot && has_markers) { |
| 493 | std::vector<std::wstring> entry_parts = dirs; | 507 | std::vector<std::wstring> entry_parts = dirs; |
| 494 | entry_parts.push_back(found.cFileName); | 508 | entry_parts.push_back(found.cFileName); |
| 495 | if (deleted(r.overlay, entry_parts)) continue; | 509 | if (deleted(r.overlay, entry_parts)) continue; |
| 496 | } | 510 | } |
| 497 | bool duplicate = false; | 511 | if (seen.insert(key(found.cFileName)).second) out.push_back(found); |
| 498 | for (const auto& e : out) | ||
| 499 | if (same_name(e.cFileName, found.cFileName)) { | ||
| 500 | duplicate = true; | ||
| 501 | break; | ||
| 502 | } | ||
| 503 | if (!duplicate) out.push_back(found); | ||
| 504 | } while (::FindNextFileW(h, &found)); | 512 | } while (::FindNextFileW(h, &found)); |
| 505 | ::FindClose(h); | 513 | ::FindClose(h); |
| 506 | }; | 514 | }; |