[PATCH] D88810: [clangd] Add isKeyword function.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 5 06:09:41 PDT 2020


hokein added inline comments.


================
Comment at: clang-tools-extra/clangd/SourceCode.cpp:638
+  // Keywords are initialized in constructor.
+  clang::IdentifierTable KeywordsTable(LangOpts);
+  return KeywordsTable.find(NewName) != KeywordsTable.end();
----------------
sammccall wrote:
> this builds a pretty decent sized hashtable for each call, because LangOpts isn't constant.
> 
> We could consider exposing getKeywordStatus from IdentifierTable.h, then we could build a StringMap<TokenKind> (once, statically) and then call getKeywordStatus to apply the per-langopts logic.
> In fact that StringMap might also be generally nice to expose in TokenKinds.h... as long as there are no conflicts.
> 
> Or we could have cache map from LangOpts to IdentifierTable, since we won't see many sets in practice.
> 
> Or maybe it doesn't matter, I suppose!
> Or maybe it doesn't matter, I suppose!
this is my impression as well, there are ~120 keywords for C++, I think the number is not too big.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D88810



More information about the cfe-commits mailing list