refactor: index source lines once per file

core.lines.LineIndex answers the line of an offset by binary search.
mame_parser and fbneo_parser counted the newlines before each match,
O(n) per set, and csharp_source kept its own copy of the index.

arcade_parent_importer reads a profile's repository slug through
core.upstream.parse_repo and refuses a source that is not on GitHub,
the only forge its fetches reach.
This commit is contained in:
Abdessamad Derraz committed 2026-11-20 20:03:20 +01:00
1 parent c63c2f369e
commit facebef9e5
5 files changed
+83 -6

No files matched your search

+4 -1
View File
@@ -11,6 +11,8 @@ import os
import re
from pathlib import Path
from core.lines import LineIndex
_ROM_ENTRY_RE = re.compile(
r'\{\s*"([^"]+)"\s*,\s*(0x[\da-fA-F]+)\s*,\s*(0x[\da-fA-F]+)\s*,\s*([^}]+)\}',
)
@@ -33,6 +35,7 @@ def find_bios_sets(source: str, filename: str) -> dict[str, dict]:
{set_name: {"source_file": str, "source_line": int}}
"""
results: dict[str, dict] = {}
lines = LineIndex(source)
for match in _BURN_DRIVER_RE.finditer(source):
body = match.group(2)
@@ -45,7 +48,7 @@ def find_bios_sets(source: str, filename: str) -> dict[str, dict]:
continue
set_name = name_match.group(1)
line_num = source[: match.start()].count("\n") + 1
line_num = lines.line(match.start())
results[set_name] = {
"source_file": filename,