[clang-tools-extra] c4dfa03 - [clang-tidy] Call StringMap::find without constructing std::string (NFC) (#115114)

via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 6 08:35:48 PST 2024


Author: Kazu Hirata
Date: 2024-11-06T08:35:44-08:00
New Revision: c4dfa03f9f44fa183daabdd4e6d760a432ef6531

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

LOG: [clang-tidy] Call StringMap::find without constructing std::string (NFC) (#115114)

StringMap::find takes StringRef, so we don't need to allocate
temporary instances of std::string.

Added: 
    

Modified: 
    clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp b/clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp
index 3d807c1d0f7aa2..4cdbbd43c14311 100644
--- a/clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp
@@ -244,7 +244,7 @@ std::optional<DurationScale> getScaleForDurationInverse(llvm::StringRef Name) {
        {"ToDoubleNanoseconds", DurationScale::Nanoseconds},
        {"ToInt64Nanoseconds", DurationScale::Nanoseconds}});
 
-  auto ScaleIter = ScaleMap.find(std::string(Name));
+  auto ScaleIter = ScaleMap.find(Name);
   if (ScaleIter == ScaleMap.end())
     return std::nullopt;
 
@@ -260,7 +260,7 @@ std::optional<DurationScale> getScaleForTimeInverse(llvm::StringRef Name) {
        {"ToUnixMicros", DurationScale::Microseconds},
        {"ToUnixNanos", DurationScale::Nanoseconds}});
 
-  auto ScaleIter = ScaleMap.find(std::string(Name));
+  auto ScaleIter = ScaleMap.find(Name);
   if (ScaleIter == ScaleMap.end())
     return std::nullopt;
 


        


More information about the cfe-commits mailing list