[PATCH] D103142: [clang][clangd] Use reverse header map lookup in suggestPathToFileForDiagnostics
Bruno Cardoso Lopes via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 1 13:01:45 PDT 2021
bruno added inline comments.
================
Comment at: clang/lib/Lex/HeaderMap.cpp:265
+ }
+ return ReverseMap.lookup(DestPath);
+}
----------------
How about something along the lines of:
```
...
StringRef Key;
for (unsigned i = 0; i != NumBuckets; ++i) {
HMapBucket B = getBucket(i);
if (B.Key == HMAP_EmptyBucketKey)
continue;
Key = getString(B.Key);
Optional<StringRef> Prefix = getString(B.Prefix);
Optional<StringRef> Suffix = getString(B.Suffix);
if (!Key.empty() && Prefix && Suffix) {
SmallVector<char, 1024> Buf;
Buf.append(Prefix->begin(), Prefix->end());
Buf.append(Suffix->begin(), Suffix->end());
ReverseMap[StringRef(Buf.begin(), Buf.size())] = Key;
break;
}
}
assert(!Key.empty() && "expected valid key");
return Key;
```
While proposing this change I've noticed that it would keep looking for other buckets even in face of a valid result, so I've added a `break`. Was that intentional?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D103142/new/
https://reviews.llvm.org/D103142
More information about the cfe-commits
mailing list