This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[6/8] save memory in init_type
- From: Tom Tromey <tromey at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Fri, 11 Jan 2013 12:28:55 -0700
- Subject: [6/8] save memory in init_type
While constifying init_type, I was curious about the strings passed to
it by its various callers.
So, I examined all the callers and what I found is that the argument is
in most cases either a constant string (not requiring copying), or NULL,
or a string already saved on the objfile obstack.
The only exception to this was a call in fixup_go_packaging.
This patch changes init_type so that it does not copy its argument, and
changes fixup_go_packaging to do the copying instead. This lets us save
some memory.
Tom
* dwarf2read.c (fixup_go_packaging): Save package name
on objfile obstack.
* gdbtypes.c (init_type): Don't copy name.
---
gdb/dwarf2read.c | 8 ++++++--
gdb/gdbtypes.c | 11 ++++-------
2 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 5368f34..af57c66 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -6826,15 +6826,19 @@ fixup_go_packaging (struct dwarf2_cu *cu)
if (package_name != NULL)
{
struct objfile *objfile = cu->objfile;
+ const char *saved_package_name = obsavestring (package_name,
+ strlen (package_name),
+ &objfile->objfile_obstack);
struct type *type = init_type (TYPE_CODE_MODULE, 0, 0,
- package_name, objfile);
+ saved_package_name, objfile);
struct symbol *sym;
TYPE_TAG_NAME (type) = TYPE_NAME (type);
sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol);
SYMBOL_SET_LANGUAGE (sym, language_go);
- SYMBOL_SET_NAMES (sym, package_name, strlen (package_name), 1, objfile);
+ SYMBOL_SET_NAMES (sym, saved_package_name,
+ strlen (saved_package_name), 0, objfile);
/* This is not VAR_DOMAIN because we want a way to ensure a lookup of,
e.g., "main" finds the "main" module and not C's main(). */
SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 62bf589..77d2a8c 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -1939,10 +1939,9 @@ allocate_gnat_aux_type (struct type *type)
/* Helper function to initialize the standard scalar types.
- If NAME is non-NULL, then we make a copy of the string pointed
- to by name in the objfile_obstack for that objfile, and initialize
- the type name to that copy. There are places (mipsread.c in particular),
- where init_type is called with a NULL value for NAME). */
+ If NAME is non-NULL, then it is used to initialize the type name.
+ Note that NAME is not copied; it is required to have a lifetime at
+ least as long as OBJFILE. */
struct type *
init_type (enum type_code code, int length, int flags,
@@ -1980,9 +1979,7 @@ init_type (enum type_code code, int length, int flags,
if (flags & TYPE_FLAG_GNU_IFUNC)
TYPE_GNU_IFUNC (type) = 1;
- if (name)
- TYPE_NAME (type) = obsavestring (name, strlen (name),
- &objfile->objfile_obstack);
+ TYPE_NAME (type) = name;
/* C++ fancies. */
--
1.7.7.6