public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Simplify event_location_probe
@ 2022-01-18 17:14 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2022-01-18 17:14 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=5947982f1dadfa72a6913f25cc4f56e137c7217e

commit 5947982f1dadfa72a6913f25cc4f56e137c7217e
Author: Tom Tromey <tom@tromey.com>
Date:   Fri Jan 14 09:06:11 2022 -0700

    Simplify event_location_probe
    
    event_location_probe currently stores two strings, but really only
    needs one.  This patch simplifies it and removes some unnecessary
    copies as well.

Diff:
---
 gdb/location.c | 35 ++++++++++++++---------------------
 gdb/location.h |  2 +-
 gdb/probe.c    |  2 +-
 3 files changed, 16 insertions(+), 23 deletions(-)

diff --git a/gdb/location.c b/gdb/location.c
index f8369bf8318..d4dfc3b8258 100644
--- a/gdb/location.c
+++ b/gdb/location.c
@@ -71,6 +71,12 @@ protected:
   {
   }
 
+  event_location (enum event_location_type t, std::string &&str)
+    : type (t),
+      as_string (std::move (str))
+  {
+  }
+
   explicit event_location (const event_location *to_clone)
     : type (to_clone->type),
       as_string (to_clone->as_string)
@@ -85,17 +91,9 @@ protected:
 /* A probe.  */
 struct event_location_probe : public event_location
 {
-  explicit event_location_probe (const char *probe)
-    : event_location (PROBE_LOCATION),
-      addr_string (probe == nullptr
-		   ? nullptr
-		   : xstrdup (probe))
-  {
-  }
-
-  ~event_location_probe ()
+  explicit event_location_probe (std::string &&probe)
+    : event_location (PROBE_LOCATION, std::move (probe))
   {
-    xfree (addr_string);
   }
 
   event_location_up clone () const override
@@ -105,24 +103,19 @@ struct event_location_probe : public event_location
 
   bool empty_p () const override
   {
-    return addr_string == nullptr;
+    return false;
   }
 
-  char *addr_string;
-
 protected:
 
   explicit event_location_probe (const event_location_probe *to_clone)
-    : event_location (to_clone),
-      addr_string (to_clone->addr_string == nullptr
-		   ? nullptr
-		   : xstrdup (to_clone->addr_string))
+    : event_location (to_clone)
   {
   }
 
   std::string compute_string () const override
   {
-    return addr_string;
+    return std::move (as_string);
   }
 };
 
@@ -357,9 +350,9 @@ get_address_string_location (const struct event_location *location)
 /* See description in location.h.  */
 
 event_location_up
-new_probe_location (const char *probe)
+new_probe_location (std::string &&probe)
 {
-  return event_location_up (new event_location_probe (probe));
+  return event_location_up (new event_location_probe (std::move (probe)));
 }
 
 /* See description in location.h.  */
@@ -368,7 +361,7 @@ const char *
 get_probe_location (const struct event_location *location)
 {
   gdb_assert (location->type == PROBE_LOCATION);
-  return ((event_location_probe *) location)->addr_string;
+  return location->to_string ();
 }
 
 /* See description in location.h.  */
diff --git a/gdb/location.h b/gdb/location.h
index 4cabf261383..848f6458e5e 100644
--- a/gdb/location.h
+++ b/gdb/location.h
@@ -169,7 +169,7 @@ extern const char *
 
 /* Create a new probe location.  */
 
-extern event_location_up new_probe_location (const char *probe);
+extern event_location_up new_probe_location (std::string &&probe);
 
 /* Return the probe location (a string) of the given event_location
    (which must be of type PROBE_LOCATION).  */
diff --git a/gdb/probe.c b/gdb/probe.c
index b8da177a0ae..689b5f022e4 100644
--- a/gdb/probe.c
+++ b/gdb/probe.c
@@ -204,7 +204,7 @@ parse_probes (const struct event_location *location,
       std::string canon (arg_start, arg_end - arg_start);
       canonical->special_display = 1;
       canonical->pre_expanded = 1;
-      canonical->location = new_probe_location (canon.c_str ());
+      canonical->location = new_probe_location (std::move (canon));
     }
 
   return result;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-01-18 17:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-18 17:14 [binutils-gdb] Simplify event_location_probe Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).