ahoppen accepted this revision.
ahoppen added inline comments.
This revision is now accepted and ready to land.


================
Comment at: clang/lib/Lex/HeaderSearch.cpp:1450
 Optional<unsigned> HeaderSearch::searchDirIdx(const DirectoryLookup &DL) const 
{
-  for (unsigned I = 0; I < SearchDirs.size(); ++I)
-    if (&SearchDirs[I] == &DL)
-      return I;
-  return None;
+  return &DL - &*SearchDirs.begin();
 }
----------------
jansvoboda11 wrote:
> ahoppen wrote:
> > Could we change this function to return an `unsigned` instead of 
> > `Optional<unsigned>` now?
> > 
> > Also, is `&DL - &*SearchDirs.begin()` safe and doesn’t trigger the issues 
> > we saw previously if start and end are allocated in different memory 
> > regions, because I don’t know.
> Yes, updating the return type makes sense now, thanks!
> 
> Yes, this should be safe as of this patch, since we're still storing 
> `DirectoryLookup` objects in `std::vector<DirectoryLookup>`. I'll be updating 
> this code when we change the storage (separate `std::vector<DirectoryLookup>` 
> for quoted, angled and system search paths).
OK, great. Makes sense. :thumbsup:


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D119722/new/

https://reviews.llvm.org/D119722

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to