diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 1bdd652b632..ac64f5c7609 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2021-04-02 Simon Marchi + + * objfiles.h (struct objfile_per_bfd_storage) : New + methods. + (struct objfile) : Use + objfile::objfile_per_bfd_storage::intern. + 2021-04-01 Simon Marchi * gdbtypes.h (TYPE_FLAG_ENUM): Remove, replace all uses diff --git a/gdb/objfiles.h b/gdb/objfiles.h index 4cd392bd7f0..e8a8b5f6de7 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -270,6 +270,23 @@ struct objfile_per_bfd_storage ~objfile_per_bfd_storage (); + /* Intern STRING in this object's string cache and return the unique copy. + The copy has the same lifetime as this object. + + STRING must be null-terminated. */ + + const char *intern (const char *str) + { + return (const char *) string_cache.insert (str, strlen (str) + 1); + } + + /* Same as the above, but for an std::string. */ + + const char *intern (const std::string &str) + { + return (const char *) string_cache.insert (str.c_str (), str.size () + 1); + } + /* The storage has an obstack of its own. */ auto_obstack storage_obstack; @@ -516,15 +533,14 @@ struct objfile lifetime as the per-BFD object. */ const char *intern (const char *str) { - return (const char *) per_bfd->string_cache.insert (str, strlen (str) + 1); + return per_bfd->intern (str); } /* Intern STRING and return the unique copy. The copy has the same lifetime as the per-BFD object. */ const char *intern (const std::string &str) { - return (const char *) per_bfd->string_cache.insert (str.c_str (), - str.size () + 1); + return per_bfd->intern (str); } /* Retrieve the gdbarch associated with this objfile. */