Optimize multi-ROM exclusion matching pass

Co-authored-by: gantoine <3247106+gantoine@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-05-21 18:51:56 +00:00
committed by GitHub
parent 5a1e238a5f
commit 98bc9a9eea
2 changed files with 38 additions and 9 deletions

View File

@@ -374,20 +374,36 @@ class FSRomsHandler(FSHandler):
def exclude_multi_roms(self, roms: list[str]) -> list[str]:
excluded_names = cm.get_config().EXCLUDED_MULTI_FILES
normalized_excluded = {
excluded_name.strip().lower() for excluded_name in excluded_names
}
excluded_files: set[str] = set()
normalized_patterns = [
excluded_name.strip().lower()
for excluded_name in excluded_names
if excluded_name.strip()
]
def has_wildcard(pattern: str) -> bool:
return any(char in pattern for char in ("*", "?", "["))
exact_matches = {
pattern for pattern in normalized_patterns if not has_wildcard(pattern)
}
wildcard_patterns = [
pattern for pattern in normalized_patterns if has_wildcard(pattern)
]
kept_roms: list[str] = []
for rom in roms:
normalized_rom_name = rom.strip().lower()
if normalized_rom_name in normalized_excluded or any(
fnmatch.fnmatch(normalized_rom_name, exc_name)
for exc_name in normalized_excluded
if normalized_rom_name in exact_matches:
continue
if any(
fnmatch.fnmatch(normalized_rom_name, pattern)
for pattern in wildcard_patterns
):
excluded_files.add(rom)
continue
return [f for f in roms if f not in excluded_files]
kept_roms.append(rom)
return kept_roms
def _build_rom_file(
self, rom: Rom, rom_path: Path, file_name: str, file_hash: FileHash