]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Use string_view in quirk_rust_enum
authorTom Tromey <tromey@adacore.com>
Wed, 14 Feb 2024 15:00:03 +0000 (08:00 -0700)
committerTom Tromey <tromey@adacore.com>
Mon, 18 Mar 2024 14:10:06 +0000 (08:10 -0600)
quirk_rust_enum makes string copies to store in an unordered_map.
However, the original strings have an appropriate lifetime, and so no
copying is needed.  With C++17, we can rely on string_view having a
std::hash specialization, so this patch changes this code to use
string_view rather than string.

gdb/dwarf2/read.c

index 4afb026b8ce95e59931967e40e1d0f4f08b46dd1..65b16719922441aa46cb76bba54f9a3c485c2f0a 100644 (file)
@@ -5955,7 +5955,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
       /* We need a way to find the correct discriminant given a
         variant name.  For convenience we build a map here.  */
       struct type *enum_type = disr_field->type ();
-      std::unordered_map<std::string, ULONGEST> discriminant_map;
+      std::unordered_map<std::string_view, ULONGEST> discriminant_map;
       for (int i = 0; i < enum_type->num_fields (); ++i)
        {
          if (enum_type->field (i).loc_kind () == FIELD_LOC_KIND_ENUMVAL)