diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-04-01 05:04:06 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-04-01 05:09:45 -0600 |
commit | c004342a27fb135b5d3fcd6817be4a2ae588668b (patch) | |
tree | cb90636a7630175773da86e2a9ce6b1c4f7d2275 | |
parent | ab02d73a5bf6369d567d408d0544748dfd0303ea (diff) |
measurestack: Try to speed up resolve_funcname()
-rw-r--r-- | build-aux/measurestack/analyze.py | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/build-aux/measurestack/analyze.py b/build-aux/measurestack/analyze.py index d4ca721..b7b8b08 100644 --- a/build-aux/measurestack/analyze.py +++ b/build-aux/measurestack/analyze.py @@ -172,27 +172,29 @@ re_node_label = re.compile( class _Graph: graph: dict[QName, Node] - qualified: dict[BaseName, set[QName]] + qualified: dict[BaseName, QName] def resolve_funcname(self, funcname: QName) -> QName | None: + s = str(funcname) + is_qualified = ":" in s + # Handle `ld --wrap` functions - if QName(f"__wrap_{str(funcname)}") in self.graph: - return QName(f"__wrap_{str(funcname)}") - if ( - str(funcname).startswith("__real_") - and QName(str(funcname)[len("__real_") :]) in self.graph - ): - funcname = QName(str(funcname)[len("__real_") :]) + if not is_qualified: + with_wrap = QName(f"__wrap_{s}") + if with_wrap in self.graph: + return with_wrap + if s.startswith("__real_"): + without_real = QName(s[len("__real_") :]) + if without_real in self.graph: + funcname = without_real # Usual case if funcname in self.graph: return funcname - # Handle `__weak` functions - if ":" not in str(funcname): - qnames = self.qualified.get(BaseName(str(funcname)), set()) - if len(qnames) == 1: - return next(name for name in qnames) + # Handle `__weak`/`[[gnu::weak]]` functions + if not is_qualified: + return self.qualified.get(BaseName(s)) return None @@ -279,7 +281,10 @@ def _make_graph( ret = _Graph() ret.graph = graph - ret.qualified = qualified + ret.qualified = {} + for bname, qnames in qualified.items(): + if len(qnames) == 1: + ret.qualified[bname] = next(name for name in qnames) return ret |