Author: Michael Buch
Date: 2025-12-23T09:06:08+01:00
New Revision: f0db054cf9a72f45cb7721f918c37305cd1d72b8

URL: 
https://github.com/llvm/llvm-project/commit/f0db054cf9a72f45cb7721f918c37305cd1d72b8
DIFF: 
https://github.com/llvm/llvm-project/commit/f0db054cf9a72f45cb7721f918c37305cd1d72b8.diff

LOG: [lldb][ObjC][NFC] Use llvm::StringRef::consume_front(char) where possible 
(#173012)

Now that the `llvm::StringRef::consume_front(char)` exists, lets use it
to replace the `consumeChar` helper.

Drive-by:
* Also use the overload where we previously had to pass a single
character as a string literal.

Added: 
    

Modified: 
    
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp

Removed: 
    


################################################################################
diff  --git 
a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp
 
b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp
index e8908393e7ace..d328cbb830828 100644
--- 
a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp
+++ 
b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp
@@ -29,15 +29,6 @@ static char popChar(llvm::StringRef &str) {
   return c;
 }
 
-static bool consumeChar(llvm::StringRef &str, char c) {
-  if (!str.starts_with(c))
-    return false;
-
-  str = str.drop_front();
-
-  return true;
-}
-
 using namespace lldb_private;
 
 AppleObjCTypeEncodingParser::AppleObjCTypeEncodingParser(
@@ -93,7 +84,7 @@ 
AppleObjCTypeEncodingParser::ReadStructElement(TypeSystemClang &ast_ctx,
                                                llvm::StringRef &type,
                                                bool for_expression) {
   StructElement retval;
-  if (type.consume_front("\"")) {
+  if (type.consume_front('"')) {
     if (auto maybe_name = ReadQuotedString(type))
       retval.name = *maybe_name;
     else
@@ -120,7 +111,7 @@ clang::QualType AppleObjCTypeEncodingParser::BuildUnion(
 clang::QualType AppleObjCTypeEncodingParser::BuildAggregate(
     TypeSystemClang &ast_ctx, llvm::StringRef &type, bool for_expression,
     char opener, char closer, uint32_t kind) {
-  if (!consumeChar(type, opener))
+  if (!type.consume_front(opener))
     return clang::QualType();
 
   std::string name(ReadStructName(type));
@@ -131,12 +122,12 @@ clang::QualType 
AppleObjCTypeEncodingParser::BuildAggregate(
 
   const bool is_templated = name.find('<') != std::string::npos;
 
-  if (!type.consume_front("="))
+  if (!type.consume_front('='))
     return clang::QualType();
   bool in_union = true;
   std::vector<StructElement> elements;
   while (in_union && !type.empty()) {
-    if (consumeChar(type, closer)) {
+    if (type.consume_front(closer)) {
       in_union = false;
       break;
     } else {
@@ -178,12 +169,12 @@ clang::QualType 
AppleObjCTypeEncodingParser::BuildAggregate(
 
 clang::QualType AppleObjCTypeEncodingParser::BuildArray(
     TypeSystemClang &ast_ctx, llvm::StringRef &type, bool for_expression) {
-  if (!consumeChar(type, _C_ARY_B))
+  if (!type.consume_front(_C_ARY_B))
     return clang::QualType();
 
   uint32_t size = ReadNumber(type);
   clang::QualType element_type(BuildType(ast_ctx, type, for_expression));
-  if (!consumeChar(type, _C_ARY_E))
+  if (!type.consume_front(_C_ARY_E))
     return clang::QualType();
 
   CompilerType array_type(ast_ctx.CreateArrayType(
@@ -200,14 +191,14 @@ clang::QualType AppleObjCTypeEncodingParser::BuildArray(
 clang::QualType AppleObjCTypeEncodingParser::BuildObjCObjectPointerType(
     TypeSystemClang &clang_ast_ctx, llvm::StringRef &type,
     bool for_expression) {
-  if (!consumeChar(type, _C_ID))
+  if (!type.consume_front(_C_ID))
     return clang::QualType();
 
   clang::ASTContext &ast_ctx = clang_ast_ctx.getASTContext();
 
   std::string name;
 
-  if (type.consume_front("\"")) {
+  if (type.consume_front('"')) {
     // We have to be careful here.  We're used to seeing
     //   @"NSString"
     // but in records it is possible that the string following an @ is the name
@@ -372,7 +363,7 @@ clang::QualType AppleObjCTypeEncodingParser::BuildType(
       return ast_ctx.getConstType(target_type);
   }
   case _C_PTR: {
-    if (!for_expression && consumeChar(type, _C_UNDEF)) {
+    if (!for_expression && type.consume_front(_C_UNDEF)) {
       // if we are not supporting the concept of unknownAny, but what is being
       // created here is an unknownAny*, then we can just get away with a void*
       // this is theoretically wrong (in the same sense as 'theoretically


        
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to