[PATCH] D102924: [clang] NFC: Replace std::pair by a struct in InitHeaderSearch

Jan Svoboda via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 21 08:44:06 PDT 2021


jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch replaces a `std::pair` by a proper struct in `InitHeaderSearch`. This will be useful in a follow-up: D102923 <https://reviews.llvm.org/D102923>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102924

Files:
  clang/lib/Frontend/InitHeaderSearch.cpp


Index: clang/lib/Frontend/InitHeaderSearch.cpp
===================================================================
--- clang/lib/Frontend/InitHeaderSearch.cpp
+++ clang/lib/Frontend/InitHeaderSearch.cpp
@@ -32,14 +32,20 @@
 using namespace clang::frontend;
 
 namespace {
+/// Holds information about a single include path.
+struct IncludePathInfo {
+  IncludeDirGroup Group;
+  DirectoryLookup Path;
+
+  IncludePathInfo(IncludeDirGroup Group, DirectoryLookup Path)
+      : Group(Group), Path(Path) {}
+};
 
 /// InitHeaderSearch - This class makes it easier to set the search paths of
 ///  a HeaderSearch object. InitHeaderSearch stores several search path lists
 ///  internally, which can be sent to a HeaderSearch object in one swoop.
 class InitHeaderSearch {
-  std::vector<std::pair<IncludeDirGroup, DirectoryLookup> > IncludePath;
-  typedef std::vector<std::pair<IncludeDirGroup,
-                      DirectoryLookup> >::const_iterator path_iterator;
+  std::vector<IncludePathInfo> IncludePath;
   std::vector<std::pair<std::string, bool> > SystemHeaderPrefixes;
   HeaderSearch &Headers;
   bool Verbose;
@@ -154,8 +160,7 @@
 
   // If the directory exists, add it.
   if (auto DE = FM.getOptionalDirectoryRef(MappedPathStr)) {
-    IncludePath.push_back(
-      std::make_pair(Group, DirectoryLookup(*DE, Type, isFramework)));
+    IncludePath.emplace_back(Group, DirectoryLookup(*DE, Type, isFramework));
     return true;
   }
 
@@ -165,9 +170,8 @@
     if (auto FE = FM.getFile(MappedPathStr)) {
       if (const HeaderMap *HM = Headers.CreateHeaderMap(*FE)) {
         // It is a headermap, add it to the search path.
-        IncludePath.push_back(
-          std::make_pair(Group,
-                         DirectoryLookup(HM, Type, Group == IndexHeaderMap)));
+        IncludePath.emplace_back(
+            Group, DirectoryLookup(HM, Type, Group == IndexHeaderMap));
         return true;
       }
     }
@@ -558,32 +562,32 @@
 
   // Quoted arguments go first.
   for (auto &Include : IncludePath)
-    if (Include.first == Quoted)
-      SearchList.push_back(Include.second);
+    if (Include.Group == Quoted)
+      SearchList.push_back(Include.Path);
 
   // Deduplicate and remember index.
   RemoveDuplicates(SearchList, 0, Verbose);
   unsigned NumQuoted = SearchList.size();
 
   for (auto &Include : IncludePath)
-    if (Include.first == Angled || Include.first == IndexHeaderMap)
-      SearchList.push_back(Include.second);
+    if (Include.Group == Angled || Include.Group == IndexHeaderMap)
+      SearchList.push_back(Include.Path);
 
   RemoveDuplicates(SearchList, NumQuoted, Verbose);
   unsigned NumAngled = SearchList.size();
 
   for (auto &Include : IncludePath)
-    if (Include.first == System || Include.first == ExternCSystem ||
-        (!Lang.ObjC && !Lang.CPlusPlus && Include.first == CSystem) ||
+    if (Include.Group == System || Include.Group == ExternCSystem ||
+        (!Lang.ObjC && !Lang.CPlusPlus && Include.Group == CSystem) ||
         (/*FIXME !Lang.ObjC && */ Lang.CPlusPlus &&
-         Include.first == CXXSystem) ||
-        (Lang.ObjC && !Lang.CPlusPlus && Include.first == ObjCSystem) ||
-        (Lang.ObjC && Lang.CPlusPlus && Include.first == ObjCXXSystem))
-      SearchList.push_back(Include.second);
+         Include.Group == CXXSystem) ||
+        (Lang.ObjC && !Lang.CPlusPlus && Include.Group == ObjCSystem) ||
+        (Lang.ObjC && Lang.CPlusPlus && Include.Group == ObjCXXSystem))
+      SearchList.push_back(Include.Path);
 
   for (auto &Include : IncludePath)
-    if (Include.first == After)
-      SearchList.push_back(Include.second);
+    if (Include.Group == After)
+      SearchList.push_back(Include.Path);
 
   // Remove duplicates across both the Angled and System directories.  GCC does
   // this and failing to remove duplicates across these two groups breaks


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102924.347045.patch
Type: text/x-patch
Size: 3862 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210521/1cf98238/attachment.bin>


More information about the cfe-commits mailing list