[PATCH] D116318: [clang-format][NFC] Fix a bug in getPreviousToken() in the parser
Owen Pan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 7 00:28:38 PST 2022
owenpan added a comment.
In D116318#3212351 <https://reviews.llvm.org/D116318#3212351>, @curdeius wrote:
> I'm in the same position as @hazardyknusperkeks.
> If you need something to simplify the code you can add a helper `getPreviousTokenOrNull` or something like that in your patch.
> But we certainly don't want to pay for the `if` check each time we call `getPreviousToken`.
I think we are going overboard here. Based on the comments, the intent was to return null for the previous token of the first token. I was the first and only one who needed to call it, and if the caller must check if it's the first token every time anyway, why not just do it in the callee and make the function more robust. Perhaps we can rename the current one to something like `getPreviousTokenFast`?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D116318/new/
https://reviews.llvm.org/D116318
More information about the cfe-commits
mailing list