Patchwork [2/4] Make obstack_strdup inline

login
register
mail settings
Submitter Tom Tromey
Date Aug. 4, 2019, 2:51 a.m.
Message ID <20190804025110.15135-3-tom@tromey.com>
Download mbox | patch
Permalink /patch/33950/
State New
Headers show

Comments

Tom Tromey - Aug. 4, 2019, 2:51 a.m.
This changes obstack_strdup to be an inline function.  This seems
better to me, considering how small it is; but also it follows what
the code did before the previous patch.

gdb/ChangeLog
2019-08-03  Tom Tromey  <tom@tromey.com>

	* gdb_obstack.h (obstack_strdup): Define.
	* gdb_obstack.c (obstack_strdup): Don't define.
---
 gdb/ChangeLog     |  5 +++++
 gdb/gdb_obstack.c | 10 ----------
 gdb/gdb_obstack.h |  6 +++++-
 3 files changed, 10 insertions(+), 11 deletions(-)
Kevin Buettner - Aug. 6, 2019, 9 p.m.
On Sat,  3 Aug 2019 20:51:08 -0600
Tom Tromey <tom@tromey.com> wrote:

> This changes obstack_strdup to be an inline function.  This seems
> better to me, considering how small it is; but also it follows what
> the code did before the previous patch.
> 
> gdb/ChangeLog
> 2019-08-03  Tom Tromey  <tom@tromey.com>
> 
> 	* gdb_obstack.h (obstack_strdup): Define.
> 	* gdb_obstack.c (obstack_strdup): Don't define.

LGTM.

Kevin

Patch

diff --git a/gdb/gdb_obstack.c b/gdb/gdb_obstack.c
index 0bf4abb82f6..01257120d07 100644
--- a/gdb/gdb_obstack.c
+++ b/gdb/gdb_obstack.c
@@ -45,13 +45,3 @@  obconcat (struct obstack *obstackp, ...)
 
   return (char *) obstack_finish (obstackp);
 }
-
-/* See gdb_obstack.h.  */
-
-char *
-obstack_strdup (struct obstack *obstackp, const char *string)
-{
-  char *obstring = (char *) obstack_alloc (obstackp, strlen (string) + 1);
-  strcpy (obstring, string);
-  return obstring;
-}
diff --git a/gdb/gdb_obstack.h b/gdb/gdb_obstack.h
index 143fcf7179f..829e2f959c4 100644
--- a/gdb/gdb_obstack.h
+++ b/gdb/gdb_obstack.h
@@ -89,7 +89,11 @@  extern char *obconcat (struct obstack *obstackp, ...) ATTRIBUTE_SENTINEL;
 /* Duplicate STRING, returning an equivalent string that's allocated on the
    obstack OBSTACKP.  */
 
-extern char *obstack_strdup (struct obstack *obstackp, const char *string);
+static inline char *
+obstack_strdup (struct obstack *obstackp, const char *string)
+{
+  return (char *) obstack_copy0 (obstackp, string, strlen (string));
+}
 
 /* An obstack that frees itself on scope exit.  */
 struct auto_obstack : obstack