https://github.com/hardikxk created https://github.com/llvm/llvm-project/pull/232260
Replace the push_back() calls with emplace_back() to allow in place construction of objects instead of the object creation and move calls done by push_back(). A constructor for `UnresolvedConflict` is also created to support the emplace_back() method. >From 506c722a83db69a9579fb1f1889f4b007c077c29 Mon Sep 17 00:00:00 2001 From: Hardik Kumar <[email protected]> Date: Thu, 15 Oct 2026 15:11:58 +0530 Subject: [PATCH] [clang][Lex] Replace push_back with emplace_back for vector insertions Replace the push_back() calls with emplace_back() to allow in place construction of objects instead of the object creation and move calls done by push_back(). A constructor for `UnresolvedConflict` is also created to support the emplace_back() method. Signed-off-by: Hardik Kumar <[email protected]> --- clang/include/clang/Basic/Module.h | 5 +++++ clang/lib/Lex/ModuleMap.cpp | 13 ++++--------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/clang/include/clang/Basic/Module.h b/clang/include/clang/Basic/Module.h index 4d304b8f006b60..28e635efc4f904 100644 --- a/clang/include/clang/Basic/Module.h +++ b/clang/include/clang/Basic/Module.h @@ -737,6 +737,11 @@ class alignas(8) Module { /// The message provided to the user when there is a conflict. std::string Message; + + /// Construct an unresolved conflict. + UnresolvedConflict() = default; + UnresolvedConflict(ModuleId Id, std::string Message) + : Id(Id), Message(Message) {} }; /// The list of conflicts for which the module-id has not yet been diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp index b75f5c98ba72bb..4d40d2d5e03c93 100644 --- a/clang/lib/Lex/ModuleMap.cpp +++ b/clang/lib/Lex/ModuleMap.cpp @@ -2301,8 +2301,8 @@ void ModuleMapLoader::handleUseDecl(const modulemap::UseDecl &UD) { } void ModuleMapLoader::handleLinkDecl(const modulemap::LinkDecl &LD) { - ActiveModule->LinkLibraries.push_back( - Module::LinkLibrary(std::string{LD.Library}, LD.Framework)); + ActiveModule->LinkLibraries.emplace_back(std::string{LD.Library}, + LD.Framework); } void ModuleMapLoader::handleConfigMacros( @@ -2322,13 +2322,8 @@ void ModuleMapLoader::handleConfigMacros( } void ModuleMapLoader::handleConflict(const modulemap::ConflictDecl &CD) { - Module::UnresolvedConflict Conflict; - - Conflict.Id = CD.Id; - Conflict.Message = CD.Message; - - // FIXME: when we move to C++20 we should consider using emplace_back - ActiveModule->UnresolvedConflicts.push_back(std::move(Conflict)); + ActiveModule->UnresolvedConflicts.emplace_back(CD.Id, + std::string{CD.Message}); } void ModuleMapLoader::handleInferredModuleDecl( _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
