llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-modules

Author: Hardik Kumar (hardikxk)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/232260.diff


2 Files Affected:

- (modified) clang/include/clang/Basic/Module.h (+5) 
- (modified) clang/lib/Lex/ModuleMap.cpp (+4-9) 


``````````diff
diff --git a/clang/include/clang/Basic/Module.h 
b/clang/include/clang/Basic/Module.h
index 4d304b8f006b6..28e635efc4f90 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 b75f5c98ba72b..4d40d2d5e03c9 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(

``````````

</details>


https://github.com/llvm/llvm-project/pull/232260
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to