[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
Sat May 4 08:55:15 PDT 2024
https://github.com/SimplyDanny created https://github.com/llvm/llvm-project/pull/91067
Fixes #90323.
>From 41650c728e226e66ebfe480066b0b6c7f24a07a6 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 da72fb511f82d8..7aea7a3b0f6d69 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