[Lldb-commits] [lldb] r334631 - [ObjC] Use llvm::StringRef in summary providers

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Wed Jun 13 11:15:14 PDT 2018


Author: jdevlieghere
Date: Wed Jun 13 11:15:14 2018
New Revision: 334631

URL: http://llvm.org/viewvc/llvm-project?rev=334631&view=rev
Log:
[ObjC] Use llvm::StringRef in summary providers

Replace const char pointers with llvm::StringRef and use its equality
operator for string comparisons.

Modified:
    lldb/trunk/source/Plugins/Language/ObjC/Cocoa.cpp

Modified: lldb/trunk/source/Plugins/Language/ObjC/Cocoa.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Language/ObjC/Cocoa.cpp?rev=334631&r1=334630&r2=334631&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Language/ObjC/Cocoa.cpp (original)
+++ lldb/trunk/source/Plugins/Language/ObjC/Cocoa.cpp Wed Jun 13 11:15:14 2018
@@ -67,12 +67,12 @@ bool lldb_private::formatters::NSBundleS
   if (!valobj_addr)
     return false;
 
-  const char *class_name = descriptor->GetClassName().GetCString();
+  llvm::StringRef class_name(descriptor->GetClassName().GetCString());
 
-  if (!class_name || !*class_name)
+  if (class_name.empty())
     return false;
 
-  if (!strcmp(class_name, "NSBundle")) {
+  if (class_name == "NSBundle") {
     uint64_t offset = 5 * ptr_size;
     ValueObjectSP text(valobj.GetSyntheticChildAtOffset(
         offset,
@@ -117,12 +117,12 @@ bool lldb_private::formatters::NSTimeZon
   if (!valobj_addr)
     return false;
 
-  const char *class_name = descriptor->GetClassName().GetCString();
+  llvm::StringRef class_name(descriptor->GetClassName().GetCString());
 
-  if (!class_name || !*class_name)
+  if (class_name.empty())
     return false;
 
-  if (!strcmp(class_name, "__NSTimeZone")) {
+  if (class_name == "__NSTimeZone") {
     uint64_t offset = ptr_size;
     ValueObjectSP text(valobj.GetSyntheticChildAtOffset(
         offset, valobj.GetCompilerType(), true));
@@ -164,12 +164,12 @@ bool lldb_private::formatters::NSNotific
   if (!valobj_addr)
     return false;
 
-  const char *class_name = descriptor->GetClassName().GetCString();
+  llvm::StringRef class_name(descriptor->GetClassName().GetCString());
 
-  if (!class_name || !*class_name)
+  if (class_name.empty())
     return false;
 
-  if (!strcmp(class_name, "NSConcreteNotification")) {
+  if (class_name == "NSConcreteNotification") {
     uint64_t offset = ptr_size;
     ValueObjectSP text(valobj.GetSyntheticChildAtOffset(
         offset, valobj.GetCompilerType(), true));
@@ -211,14 +211,14 @@ bool lldb_private::formatters::NSMachPor
   if (!valobj_addr)
     return false;
 
-  const char *class_name = descriptor->GetClassName().GetCString();
+  llvm::StringRef class_name(descriptor->GetClassName().GetCString());
 
-  if (!class_name || !*class_name)
+  if (class_name.empty())
     return false;
 
   uint64_t port_number = 0;
 
-  if (!strcmp(class_name, "NSMachPort")) {
+  if (class_name == "NSMachPort") {
     uint64_t offset = (ptr_size == 4 ? 12 : 20);
     Status error;
     port_number = process_sp->ReadUnsignedIntegerFromMemory(
@@ -259,16 +259,15 @@ bool lldb_private::formatters::NSIndexSe
   if (!valobj_addr)
     return false;
 
-  const char *class_name = descriptor->GetClassName().GetCString();
+  llvm::StringRef class_name(descriptor->GetClassName().GetCString());
 
-  if (!class_name || !*class_name)
+  if (class_name.empty())
     return false;
 
   uint64_t count = 0;
 
   do {
-    if (!strcmp(class_name, "NSIndexSet") ||
-        !strcmp(class_name, "NSMutableIndexSet")) {
+    if (class_name == "NSIndexSet" || class_name == "NSMutableIndexSet") {
       Status error;
       uint32_t mode = process_sp->ReadUnsignedIntegerFromMemory(
           valobj_addr + ptr_size, 4, 0, error);
@@ -451,15 +450,15 @@ bool lldb_private::formatters::NSNumberS
   if (!valobj_addr)
     return false;
 
-  const char *class_name = descriptor->GetClassName().GetCString();
+  llvm::StringRef class_name(descriptor->GetClassName().GetCString());
 
-  if (!class_name || !*class_name)
+  if (class_name.empty())
     return false;
 
-  if (!strcmp(class_name, "__NSCFBoolean"))
+  if (class_name == "__NSCFBoolean")
     return ObjCBooleanSummaryProvider(valobj, stream, options);
 
-  if (!strcmp(class_name, "NSNumber") || !strcmp(class_name, "__NSCFNumber")) {
+  if (class_name == "NSNumber" || class_name == "__NSCFNumber") {
     uint64_t value = 0;
     uint64_t i_bits = 0;
     if (descriptor->GetTaggedPointerInfo(&i_bits, &value)) {




More information about the lldb-commits mailing list