[Lldb-commits] [lldb] ab27431 - [lldb][NFCI] Remove use of ConstString from UnixSignals::SignalCode

Alex Langford via lldb-commits lldb-commits at lists.llvm.org
Thu Jun 1 10:04:46 PDT 2023


Author: Alex Langford
Date: 2023-06-01T10:03:56-07:00
New Revision: ab27431596c4f61f84ce41e27aad09a4dde3fc5a

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

LOG: [lldb][NFCI] Remove use of ConstString from UnixSignals::SignalCode

On llvm.org and all downstream forks that I'm aware of, SignalCodes are
always created from C string literals. They are never compared to
anything so they take up space in the ConstString StringPool for no
tangible benefit.

I've changed the type here to `const llvm::StringLiteral` instead of
using a `StringRef` or a `const char *` to express intent -- These
strings come from constant data whose lifetime is directly tied to that
of the running process (and are thus safe to store).

Differential Revision: https://reviews.llvm.org/D151516

Added: 
    

Modified: 
    lldb/include/lldb/Target/UnixSignals.h
    lldb/source/Target/UnixSignals.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Target/UnixSignals.h b/lldb/include/lldb/Target/UnixSignals.h
index 859cf0c814f69..74eb75fa23aa4 100644
--- a/lldb/include/lldb/Target/UnixSignals.h
+++ b/lldb/include/lldb/Target/UnixSignals.h
@@ -94,7 +94,7 @@ class UnixSignals {
   // Instead of calling this directly, use a ADD_SIGCODE macro to get compile
   // time checks when on the native platform.
   void AddSignalCode(
-      int signo, int code, const char *description,
+      int signo, int code, const llvm::StringLiteral description,
       SignalCodePrintOption print_option = SignalCodePrintOption::None);
 
   void RemoveSignal(int signo);
@@ -127,8 +127,8 @@ class UnixSignals {
   // Classes that inherit from UnixSignals can see and modify these
 
   struct SignalCode {
-    ConstString m_description;
-    SignalCodePrintOption m_print_option;
+    const llvm::StringLiteral m_description;
+    const SignalCodePrintOption m_print_option;
   };
 
   struct Signal {

diff  --git a/lldb/source/Target/UnixSignals.cpp b/lldb/source/Target/UnixSignals.cpp
index d754537cc4cf4..5d0f687b8ba6f 100644
--- a/lldb/source/Target/UnixSignals.cpp
+++ b/lldb/source/Target/UnixSignals.cpp
@@ -113,13 +113,14 @@ void UnixSignals::AddSignal(int signo, const char *name, bool default_suppress,
   ++m_version;
 }
 
-void UnixSignals::AddSignalCode(int signo, int code, const char *description,
+void UnixSignals::AddSignalCode(int signo, int code,
+                                const llvm::StringLiteral description,
                                 SignalCodePrintOption print_option) {
   collection::iterator signal = m_signals.find(signo);
   assert(signal != m_signals.end() &&
          "Tried to add code to signal that does not exist.");
   signal->second.m_codes.insert(
-      std::pair{code, SignalCode{ConstString(description), print_option}});
+      std::pair{code, SignalCode{description, print_option}});
   ++m_version;
 }
 
@@ -150,13 +151,13 @@ UnixSignals::GetSignalDescription(int32_t signo, std::optional<int32_t> code,
     str = pos->second.m_name.GetCString();
 
     if (code) {
-      std::map<int, SignalCode>::const_iterator cpos =
+      std::map<int32_t, SignalCode>::const_iterator cpos =
           pos->second.m_codes.find(*code);
       if (cpos != pos->second.m_codes.end()) {
         const SignalCode &sc = cpos->second;
         str += ": ";
         if (sc.m_print_option != SignalCodePrintOption::Bounds)
-          str += sc.m_description.GetCString();
+          str += sc.m_description.str();
 
         std::stringstream strm;
         switch (sc.m_print_option) {
@@ -178,7 +179,7 @@ UnixSignals::GetSignalDescription(int32_t signo, std::optional<int32_t> code,
             strm << ", upper bound: 0x" << std::hex << *upper;
             strm << ")";
           } else
-            strm << sc.m_description.GetCString();
+            strm << sc.m_description.str();
 
           break;
         }


        


More information about the lldb-commits mailing list