diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 441a2524..9910cf43 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -2136,7 +2136,7 @@ std::string Converter::ConvertDeclRefExpr(clang::DeclRefExpr *expr) { return std::format("{}::{}", GetRecordName(clang::dyn_cast( enum_constant->getDeclContext())), - enum_constant->getName().str()); + std::string_view(enum_constant->getName())); } else if (IsGlobalVar(expr)) { return ReplaceAll(Mapper::ToString(expr->getDecl()), "::", "_"); } @@ -2612,12 +2612,12 @@ bool Converter::VisitEnumDecl(clang::EnumDecl *decl) { for (auto e : decl->enumerators()) { llvm::SmallVector init; e->getInitVal().toString(init, 10); - std::string init_str(init.begin(), init.end()); if (first_enumerator) { StrCat("#[default]"); first_enumerator = false; } - StrCat(std::format("{} = {},", e->getNameAsString(), init_str)); + StrCat(std::format("{} = {},", std::string_view(e->getName()), + std::string_view(init.data(), init.size()))); } StrCat("}"); return false; @@ -2854,7 +2854,7 @@ std::string Converter::ConvertVarDefaultInit(clang::QualType qual_type) { std::string Converter::GetOverloadedFunctionName(const clang::FunctionDecl *decl) { - std::string name(decl->getNameAsString()); + auto name = decl->getNameAsString(); if (decl->getNumParams() != 0U) { name += '_'; diff --git a/cpp2rust/converter/mapper.cpp b/cpp2rust/converter/mapper.cpp index e0866206..45d88bae 100644 --- a/cpp2rust/converter/mapper.cpp +++ b/cpp2rust/converter/mapper.cpp @@ -443,7 +443,7 @@ void addBuiltinTypes(Model model) { auto build_rust_type = [&](clang::QualType qt) { unsigned bits = ctx_->getTypeSize(qt); char sign = qt->isSignedIntegerType() ? 'i' : 'u'; - return std::string(1, sign) + std::to_string(bits); + return std::format("{}{}", sign, bits); }; // Misc @@ -858,10 +858,11 @@ std::string ToString(const clang::Expr *expr) { } if (const auto *uop = llvm::dyn_cast(expr)) { - std::string opcode = - clang::UnaryOperator::getOpcodeStr(uop->getOpcode()).str(); - return uop->isPostfix() ? ToString(uop->getSubExpr()) + std::move(opcode) - : std::move(opcode) + ToString(uop->getSubExpr()); + auto sub = ToString(uop->getSubExpr()); + std::string_view opcode = + clang::UnaryOperator::getOpcodeStr(uop->getOpcode()); + return uop->isPostfix() ? std::format("{}{}", sub, opcode) + : std::format("{}{}", opcode, sub); } return "Unhandled case in ToString"; diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index 3cf69347..eedb1606 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -1757,7 +1757,7 @@ void ConverterRefCount::ConvertGenericBinaryOperator( clang::BinaryOperator *expr) { auto lhs = expr->getLHS(); auto rhs = expr->getRHS(); - auto opcode = expr->getOpcodeStr().str(); + std::string_view opcode = expr->getOpcodeStr(); auto lhs_vars = GetAllVars(lhs); auto rhs_vars = GetAllVars(rhs);