[llvm] [XRay] Use llvm::is_contained (NFC) (PR #141318)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Fri May 23 19:53:53 PDT 2025


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/141318

None

>From 6ec1dd4c40092d6f6934c5b4e690a0c25eab089d Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Thu, 15 May 2025 21:28:40 -0700
Subject: [PATCH] [XRay] Use llvm::is_contained (NFC)

---
 llvm/unittests/XRay/GraphTest.cpp | 40 ++++++++-----------------------
 1 file changed, 10 insertions(+), 30 deletions(-)

diff --git a/llvm/unittests/XRay/GraphTest.cpp b/llvm/unittests/XRay/GraphTest.cpp
index faf10ea96ce2e..37f07cc721c61 100644
--- a/llvm/unittests/XRay/GraphTest.cpp
+++ b/llvm/unittests/XRay/GraphTest.cpp
@@ -72,9 +72,7 @@ template <typename T> void graphVertexTester(T &G) {
     ASSERT_TRUE(!!EVV);
     EXPECT_EQ(1u, G.count(u));
     EXPECT_EQ(VA[u], EVV->VA);
-    EXPECT_NE(G.vertices().end(),
-              llvm::find_if(G.vertices(),
-                            [&](const VVT &VV) { return VV.first == u; }));
+    EXPECT_TRUE(llvm::is_contained(llvm::make_first_range(G.vertices()), u));
     consumeError(EVV.takeError());
   }
 
@@ -97,8 +95,7 @@ template <typename T> void graphEdgeTester(T &G) {
     EXPECT_EQ(1u, G.count(u));
     EXPECT_EQ(VA[u.first] * VA[u.second] * ((u.first > u.second) ? 2 : 1),
               EEV->EA);
-    auto Pred = [&](const EVT &EV) { return EV.first == u; };
-    EXPECT_NE(G.edges().end(), llvm::find_if(G.edges(), Pred));
+    EXPECT_TRUE(llvm::is_contained(llvm::make_first_range(G.edges()), u));
     consumeError(EEV.takeError());
   }
 
@@ -113,31 +110,14 @@ template <typename T> void graphEdgeTester(T &G) {
     EXPECT_NE(OE.size(), 0u);
     EXPECT_NE(IE.begin(), IE.end());
     EXPECT_NE(OE.begin(), OE.end());
-    {
-      auto It = std::find_if(
-          G.inEdges(EV.first.second).begin(), G.inEdges(EV.first.second).end(),
-          [&](const EVT &EVI) { return EVI.first == EV.first; });
-      EXPECT_NE(G.inEdges(EV.first.second).end(), It);
-    }
-    {
-      auto It = std::find_if(
-          G.inEdges(EV.first.first).begin(), G.inEdges(EV.first.first).end(),
-          [&](const EVT &EVI) { return EVI.first == EV.first; });
-      EXPECT_EQ(G.inEdges(EV.first.first).end(), It);
-    }
-    {
-      auto It =
-          std::find_if(G.outEdges(EV.first.second).begin(),
-                       G.outEdges(EV.first.second).end(),
-                       [&](const EVT &EVI) { return EVI.first == EV.first; });
-      EXPECT_EQ(G.outEdges(EV.first.second).end(), It);
-    }
-    {
-      auto It = std::find_if(
-          G.outEdges(EV.first.first).begin(), G.outEdges(EV.first.first).end(),
-          [&](const EVT &EVI) { return EVI.first == EV.first; });
-      EXPECT_NE(G.outEdges(EV.first.first).end(), It);
-    }
+    EXPECT_TRUE(llvm::is_contained(
+        llvm::make_first_range(G.inEdges(EV.first.second)), EV.first));
+    EXPECT_FALSE(llvm::is_contained(
+        llvm::make_first_range(G.inEdges(EV.first.first)), EV.first));
+    EXPECT_FALSE(llvm::is_contained(
+        llvm::make_first_range(G.outEdges(EV.first.second)), EV.first));
+    EXPECT_TRUE(llvm::is_contained(
+        llvm::make_first_range(G.outEdges(EV.first.first)), EV.first));
   }
 }
 



More information about the llvm-commits mailing list