[clang-tools-extra] [clang-tidy] Call StringMap::find without constructing std::string (NFC) (PR #115114)
Kazu Hirata via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 5 20:57:54 PST 2024
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/115114
StringMap::find takes StringRef, so we don't need to allocate
temporary instances of std::string.
>From 9614bd57bc2175e6f66bb251294dffc0855fa459 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Tue, 5 Nov 2024 10:09:12 -0800
Subject: [PATCH] [clang-tidy] Call StringMap::find without constructing
std::string (NFC)
StringMap::find takes StringRef, so we don't need to allocate
temporary instances of std::string.
---
clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
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