mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-27 20:08:51 -06:00
refactor: reuse the shared helpers left copied
Copies of helpers the first pass created, replaced by the helper: - source_yaml_file for our YAML sources (generate_db read them in the locale's encoding, a syntax error named no file); - data_dir_registry_at in registry_bundles, platform_registry_at (new, beside load_platform_registry) in the manifest; - DATA_DIRS_FILE for the registry path five modules spelled; - load_optional_database, sha1_at, VERSIONS_FILE, installer_module; - DerivedView where a cache was keyed by id() of a dict; - count_text and series where a plural or a list was written by hand.
This commit is contained in:
1 parent
32a4ca1fa1
commit
036a6ebf29
35 files changed
+141
-170
No files matched your search
@@ -2,10 +2,12 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from core.memo import DerivedView
|
||||
from resolve.validation import read_by_build
|
||||
|
||||
|
||||
_directory_members_cache: dict[int, tuple[dict, dict[str, dict[str, str]]]] = {}
|
||||
# The members found under each tail, kept per by_path_suffix index.
|
||||
_directory_members_cache: DerivedView[dict[str, dict[str, str]]] = DerivedView(lambda _index: {})
|
||||
|
||||
|
||||
def directory_members(db: dict, directory: str) -> dict[str, str]:
|
||||
@@ -24,12 +26,9 @@ def directory_members(db: dict, directory: str) -> dict[str, str]:
|
||||
if not tail:
|
||||
return {}
|
||||
by_path_suffix = db.get("indexes", {}).get("by_path_suffix", {})
|
||||
cached = _directory_members_cache.get(id(by_path_suffix))
|
||||
if cached is None or cached[0] is not by_path_suffix:
|
||||
cached = (by_path_suffix, {})
|
||||
_directory_members_cache[id(by_path_suffix)] = cached
|
||||
if tail in cached[1]:
|
||||
return cached[1][tail]
|
||||
found = _directory_members_cache(by_path_suffix)
|
||||
if tail in found:
|
||||
return found[tail]
|
||||
|
||||
prefix = f"{tail}/"
|
||||
infix = f"/{prefix}"
|
||||
@@ -54,7 +53,7 @@ def directory_members(db: dict, directory: str) -> dict[str, str]:
|
||||
if one_tree and one_content
|
||||
else {}
|
||||
)
|
||||
cached[1][tail] = members
|
||||
found[tail] = members
|
||||
return members
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user