[llvm] [NFC] Prefer `str.resize(len)` over `str.substr(0, len)` (PR #91067)
Danny Mösch via llvm-commits
llvm-commits at lists.llvm.org
Wed May 8 12:17:53 PDT 2024
https://github.com/SimplyDanny updated https://github.com/llvm/llvm-project/pull/91067
>From 4ff3e0e5a50724fd309df5a19e901c6ad490315f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Danny=20M=C3=B6sch?= <danny.moesch at icloud.com>
Date: Sat, 4 May 2024 17:53:36 +0200
Subject: [PATCH] [NFC] Prefer `str.resize(len)` over `str.substr(0, len)`
---
llvm/include/llvm/Analysis/DOTGraphTraitsPass.h | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h b/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h
index da72fb511f82d..7aea7a3b0f6d6 100644
--- a/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h
+++ b/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h
@@ -87,13 +87,12 @@ struct DOTGraphTraitsViewer
};
static inline void shortenFileName(std::string &FN, unsigned char len = 250) {
-
- FN = FN.substr(0, len);
-
+ if (FN.length() > len)
+ FN.resize(len);
auto strLen = FN.length();
while (strLen > 0) {
- if (auto it = nameObj.find(FN); it != nameObj.end()) {
- FN = FN.substr(0, --len);
+ if (nameObj.find(FN) != nameObj.end()) {
+ FN.resize(--len);
} else {
nameObj.insert(FN);
break;
More information about the llvm-commits
mailing list