[PATCH] D119722: [clang][lex] Use `SearchDirIterator` types in for loops
Alex Hoppen via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 14 09:36:40 PST 2022
ahoppen added a comment.
Nice. I think this reads a lot better than the index-based implementation.
================
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();
}
----------------
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.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D119722/new/
https://reviews.llvm.org/D119722
More information about the cfe-commits
mailing list