[clang-tools-extra] 2d014b7 - [test][clangd] Use StringRef instead of std::string

Vitaly Buka via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 25 16:38:27 PDT 2022


Author: Vitaly Buka
Date: 2022-04-25T16:38:18-07:00
New Revision: 2d014b72ccb51de9a9627c31667a3edf8cca7616

URL: https://github.com/llvm/llvm-project/commit/2d014b72ccb51de9a9627c31667a3edf8cca7616
DIFF: https://github.com/llvm/llvm-project/commit/2d014b72ccb51de9a9627c31667a3edf8cca7616.diff

LOG: [test][clangd] Use StringRef instead of std::string

runWithAST stores the first parameters as StringRef, so we can't
use temporarily std::string from parameter ID.

Added: 
    

Modified: 
    clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp b/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
index 1aaac829d6285..919f69c378403 100644
--- a/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
+++ b/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
@@ -281,22 +281,22 @@ TEST_F(TUSchedulerTests, Cancellation) {
   //    R2B
   //   U3(WantDiags=Yes)
   //    R3               <-- cancelled
-  std::vector<std::string> DiagsSeen, ReadsSeen, ReadsCanceled;
+  std::vector<StringRef> DiagsSeen, ReadsSeen, ReadsCanceled;
   {
     Notification Proceed; // Ensure we schedule everything.
     TUScheduler S(CDB, optsForTest(), captureDiags());
     auto Path = testPath("foo.cpp");
     // Helper to schedule a named update and return a function to cancel it.
-    auto Update = [&](std::string ID) -> Canceler {
+    auto Update = [&](StringRef ID) -> Canceler {
       auto T = cancelableTask();
       WithContext C(std::move(T.first));
       updateWithDiags(
-          S, Path, "//" + ID, WantDiagnostics::Yes,
+          S, Path, ("//" + ID).str(), WantDiagnostics::Yes,
           [&, ID](std::vector<Diag> Diags) { DiagsSeen.push_back(ID); });
       return std::move(T.second);
     };
     // Helper to schedule a named read and return a function to cancel it.
-    auto Read = [&](std::string ID) -> Canceler {
+    auto Read = [&](StringRef ID) -> Canceler {
       auto T = cancelableTask();
       WithContext C(std::move(T.first));
       S.runWithAST(ID, Path, [&, ID](llvm::Expected<InputsAndAST> E) {


        


More information about the cfe-commits mailing list