[Lldb-commits] [lldb] [lldb] Refactor TypeQuery::ContextMatches, take 2 (PR #101333)

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Mon Aug 5 05:16:52 PDT 2024


================
@@ -153,19 +127,36 @@ void TypeQuery::SetLanguages(LanguageSet languages) {
 
 bool TypeQuery::ContextMatches(
     llvm::ArrayRef<CompilerContext> context_chain) const {
-  if (GetExactMatch() || context_chain.size() == m_context.size())
-    return ::contextMatches(context_chain, m_context);
+  auto ctx = context_chain.rbegin(), ctx_end = context_chain.rend();
+  for (auto pat = m_context.rbegin(), pat_end = m_context.rend();
+       pat != pat_end;) {
+
+    if (ctx == ctx_end)
+      return false; // Pattern too long.
+
+    // See if there is a kind mismatch; they should have 1 bit in common.
+    if ((ctx->kind & pat->kind) == CompilerContextKind())
+      return false;
+
+    if (ctx->name != pat->name)
+      return false;
+
+    ++ctx;
+    ++pat;
+  }
+
+  // Skip over any remaining module entries if we were asked to do that.
+  while (GetIgnoreModules() && ctx != ctx_end &&
----------------
labath wrote:

Yeah, I've thought about that when writing this, but I figured that we shouldn't make the compiler's job too easy :)

I also tried a version with std::find, but that ended up even longer.

https://github.com/llvm/llvm-project/pull/101333


More information about the lldb-commits mailing list