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
@@ -13,6 +13,8 @@ import os
import re
from pathlib import Path
from core.lines import LineIndex
# Macros that declare a machine entry. GAMEL is GAME plus a layout and is
# the only suffixed form MAME declares (src/emu/gamedrv.h): a BIOS root that
# ships a layout, such as gq863 or aristmk5, is written with it.
@@ -126,6 +128,7 @@ def find_bios_root_sets(source: str, filename: str) -> dict[str, dict]:
MACHINE_IS_BIOS_ROOT, returns set names with source location.
"""
results: dict[str, dict] = {}
lines = LineIndex(source)
for match in MACHINE_MACROS.finditer(source):
start = match.end() - 1 # position of opening paren
@@ -154,7 +157,7 @@ def find_bios_root_sets(source: str, filename: str) -> dict[str, dict]:
continue
set_name = args[1].strip()
line_no = source[: match.start()].count("\n") + 1
line_no = lines.line(match.start())
results[set_name] = {
"source_file": filename,