From d93ad3aedbb49e7c0ab1255da17a9f5757c5b414 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Sun, 26 Apr 2020 13:06:50 +0200 Subject: [PATCH] [IR] Simplify code to print string attributes a bit. NFC. --- llvm/lib/IR/Attributes.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp index 2d991041..28e0505 100644 --- a/llvm/lib/IR/Attributes.cpp +++ b/llvm/lib/IR/Attributes.cpp @@ -504,19 +504,19 @@ std::string Attribute::getAsString(bool InAttrGrp) const { // if (isStringAttribute()) { std::string Result; - Result += (Twine('"') + getKindAsString() + Twine('"')).str(); - - std::string AttrVal = std::string(pImpl->getValueAsString()); - if (AttrVal.empty()) return Result; - - // Since some attribute strings contain special characters that cannot be - // printable, those have to be escaped to make the attribute value printable - // as is. e.g. "\01__gnu_mcount_nc" { raw_string_ostream OS(Result); - OS << "=\""; - printEscapedString(AttrVal, OS); - OS << "\""; + OS << '"' << getKindAsString() << '"'; + + // Since some attribute strings contain special characters that cannot be + // printable, those have to be escaped to make the attribute value + // printable as is. e.g. "\01__gnu_mcount_nc" + const auto &AttrVal = pImpl->getValueAsString(); + if (!AttrVal.empty()) { + OS << "=\""; + printEscapedString(AttrVal, OS); + OS << "\""; + } } return Result; } -- 2.7.4