Skip to content

Commit

Permalink
Lookup via ID was quadratic in mdn's panelsFromData. Precompute the m…
Browse files Browse the repository at this point in the history
…ap instead, function disappears in the noise.
  • Loading branch information
tabatkins committed Jan 24, 2025
1 parent c73ebe6 commit 901d2bd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions bikeshed/h/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
clearContents,
closestAncestor,
closestAttr,
collectIds,
createElement,
dedupIDs,
emptyText,
Expand Down
11 changes: 11 additions & 0 deletions bikeshed/h/dom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,17 @@ def circledDigits(num: int) -> str:
return result


def collectIds(el: t.ElementT, ids: dict[str, t.ElementT]|None = None) -> dict[str, t.ElementT]:
if ids is None:
ids: dict[str, t.ElementT] = {}
id = el.get("id", "")
if id and id not in ids:
ids[id] = el
for child in childElements(el):
collectIds(child, ids)
return ids


def createElement(tag: str, attrs: t.Mapping[str, str | None] | None = None, *children: t.NodesT | None) -> t.ElementT:
if attrs is None:
attrs = {}
Expand Down
3 changes: 2 additions & 1 deletion bikeshed/mdn/mdnspeclinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,13 @@ def panelsFromData(doc: t.SpecT, data: MdnDataT) -> list[t.ElementT]:

panels = []
missingIds = []
docIds = h.collectIds(doc.body)
for elementId, features in data.items():
lessThanTwoEngines = 0
onlyTwoEngines = 0
allEngines = 0
featureDivs = []
targetElement = h.find(f"[id='{elementId}']", doc)
targetElement = docIds.get(elementId)
if targetElement is None and elementId not in doc.md.ignoreMDNFailure:
missingIds.append(elementId)
continue
Expand Down

0 comments on commit 901d2bd

Please sign in to comment.