[PATCH] D116186: Comment parsing: Simplify Lexer::skipLineStartingDecorations (NFC)

Aaron Puchert via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 22 12:56:07 PST 2021


aaronpuchert created this revision.
aaronpuchert added a reviewer: gribozavr2.
aaronpuchert requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Inspection of the first character can just be handled by the loop as
well, it does exactly the same thing. Dereferencing the pointer a second
time shouldn't be an issue: the middle end can eliminate that second
read as it's separated from the first only by a pure function call.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116186

Files:
  clang/lib/AST/CommentLexer.cpp


Index: clang/lib/AST/CommentLexer.cpp
===================================================================
--- clang/lib/AST/CommentLexer.cpp
+++ clang/lib/AST/CommentLexer.cpp
@@ -94,31 +94,12 @@
   if (BufferPtr == CommentEnd)
     return;
 
-  switch (*BufferPtr) {
-  case ' ':
-  case '\t':
-  case '\f':
-  case '\v': {
-    const char *NewBufferPtr = BufferPtr;
-    NewBufferPtr++;
-    if (NewBufferPtr == CommentEnd)
+  const char *NewBufferPtr = BufferPtr;
+  while (isHorizontalWhitespace(*NewBufferPtr))
+    if (++NewBufferPtr == CommentEnd)
       return;
-
-    char C = *NewBufferPtr;
-    while (isHorizontalWhitespace(C)) {
-      NewBufferPtr++;
-      if (NewBufferPtr == CommentEnd)
-        return;
-      C = *NewBufferPtr;
-    }
-    if (C == '*')
-      BufferPtr = NewBufferPtr + 1;
-    break;
-  }
-  case '*':
-    BufferPtr++;
-    break;
-  }
+  if (*NewBufferPtr == '*')
+    BufferPtr = NewBufferPtr + 1;
 }
 
 namespace {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116186.395921.patch
Type: text/x-patch
Size: 957 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211222/b4f4a31e/attachment.bin>


More information about the cfe-commits mailing list