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

Alex Langford via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu May 25 16:30:25 PDT 2023


bulbazord created this revision.
bulbazord added reviewers: JDevlieghere, labath, DavidSpickett.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

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).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151516

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


Index: lldb/source/Target/UnixSignals.cpp
===================================================================
--- lldb/source/Target/UnixSignals.cpp
+++ lldb/source/Target/UnixSignals.cpp
@@ -113,13 +113,14 @@
   ++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 @@
     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 @@
             strm << ", upper bound: 0x" << std::hex << *upper;
             strm << ")";
           } else
-            strm << sc.m_description.GetCString();
+            strm << sc.m_description.str();
 
           break;
         }
Index: lldb/include/lldb/Target/UnixSignals.h
===================================================================
--- lldb/include/lldb/Target/UnixSignals.h
+++ lldb/include/lldb/Target/UnixSignals.h
@@ -94,7 +94,7 @@
   // 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 @@
   // 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 {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151516.525869.patch
Type: text/x-patch
Size: 2614 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230525/a04d4259/attachment.bin>


More information about the lldb-commits mailing list