[Lldb-commits] [lldb] r351264 - Simplify code by using Optional::getValueOr()

Adrian Prantl via lldb-commits lldb-commits at lists.llvm.org
Tue Jan 15 14:30:01 PST 2019


Author: adrian
Date: Tue Jan 15 14:30:01 2019
New Revision: 351264

URL: http://llvm.org/viewvc/llvm-project?rev=351264&view=rev
Log:
Simplify code by using Optional::getValueOr()

Modified:
    lldb/trunk/source/Core/ValueObjectVariable.cpp
    lldb/trunk/source/Plugins/ABI/SysV-ppc64/ABISysV_ppc64.cpp
    lldb/trunk/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp
    lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp

Modified: lldb/trunk/source/Core/ValueObjectVariable.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObjectVariable.cpp?rev=351264&r1=351263&r2=351264&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObjectVariable.cpp (original)
+++ lldb/trunk/source/Core/ValueObjectVariable.cpp Tue Jan 15 14:30:01 2019
@@ -112,9 +112,7 @@ uint64_t ValueObjectVariable::GetByteSiz
   if (!type.IsValid())
     return 0;
 
-  llvm::Optional<uint64_t> size =
-      type.GetByteSize(exe_ctx.GetBestExecutionContextScope());
-  return size ? *size : 0;
+  return type.GetByteSize(exe_ctx.GetBestExecutionContextScope()).getValueOr(0);
 }
 
 lldb::ValueType ValueObjectVariable::GetValueType() const {

Modified: lldb/trunk/source/Plugins/ABI/SysV-ppc64/ABISysV_ppc64.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ABI/SysV-ppc64/ABISysV_ppc64.cpp?rev=351264&r1=351263&r2=351264&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ABI/SysV-ppc64/ABISysV_ppc64.cpp (original)
+++ lldb/trunk/source/Plugins/ABI/SysV-ppc64/ABISysV_ppc64.cpp Tue Jan 15 14:30:01 2019
@@ -577,8 +577,7 @@ private:
   ReturnValueExtractor(Thread &thread, CompilerType &type,
                        RegisterContext *reg_ctx, ProcessSP process_sp)
       : m_thread(thread), m_type(type),
-        m_byte_size(m_type.GetByteSize(nullptr) ? *m_type.GetByteSize(nullptr)
-                                                : 0),
+        m_byte_size(m_type.GetByteSize(nullptr).getValueOr(0)),
         m_data_ap(new DataBufferHeap(m_byte_size, 0)), m_reg_ctx(reg_ctx),
         m_process_sp(process_sp), m_byte_order(process_sp->GetByteOrder()),
         m_addr_size(

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp?rev=351264&r1=351263&r2=351264&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp Tue Jan 15 14:30:01 2019
@@ -337,9 +337,7 @@ bool IRForTarget::CreateResultVariable(l
   if (log)
     log->Printf("Creating a new result global: \"%s\" with size 0x%" PRIx64,
                 m_result_name.GetCString(),
-                m_result_type.GetByteSize(nullptr)
-                    ? *m_result_type.GetByteSize(nullptr)
-                    : 0);
+                m_result_type.GetByteSize(nullptr).getValueOr(0));
 
   // Construct a new result global and set up its metadata
 

Modified: lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp?rev=351264&r1=351263&r2=351264&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp (original)
+++ lldb/trunk/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp Tue Jan 15 14:30:01 2019
@@ -513,11 +513,11 @@ void ClassDescriptorV2::iVarsStorage::fi
     CompilerType ivar_type =
         encoding_to_type_sp->RealizeType(type, for_expression);
     if (ivar_type) {
-      llvm::Optional<uint64_t> ivar_size = ivar_type.GetByteSize(nullptr);
       LLDB_LOGV(log,
                 "name = {0}, encoding = {1}, offset_ptr = {2:x}, size = "
                 "{3}, type_size = {4}",
-                name, type, offset_ptr, size, ivar_size ? *ivar_size : 0);
+                name, type, offset_ptr, size,
+                ivar_type.GetByteSize(nullptr).getValueOr(0));
       Scalar offset_scalar;
       Status error;
       const int offset_ptr_size = 4;




More information about the lldb-commits mailing list