diff options
author | Lancelot Six <lancelot.six@amd.com> | 2023-10-13 10:17:02 +0000 |
---|---|---|
committer | Lancelot Six <lancelot.six@amd.com> | 2023-11-21 11:52:36 +0000 |
commit | 8082468ffe65095cdd640fb081b9d3d28dd7add4 (patch) | |
tree | 4e9ab5a6ad254f77e96e295d873a1d5b31cf44fa /gdbsupport | |
parent | 42742fc5817a8f2e47c711880501073a9ad86cfc (diff) | |
download | fsf-binutils-gdb-8082468ffe65095cdd640fb081b9d3d28dd7add4.zip fsf-binutils-gdb-8082468ffe65095cdd640fb081b9d3d28dd7add4.tar.gz fsf-binutils-gdb-8082468ffe65095cdd640fb081b9d3d28dd7add4.tar.bz2 |
gdb: Use std::string_view instead of gdb::string_view
Given that GDB now requires a C++17, replace all uses of
gdb::string_view with std::string_view.
This change has mostly been done automatically:
- gdb::string_view -> std::string_view
- #include "gdbsupport/gdb_string_view.h" -> #include <string_view>
One things which got brought up during review is that gdb::stging_view
does support being built from "nullptr" while std::sting_view does not.
Two places are manually adjusted to account for this difference:
gdb/tui/tui-io.c:tui_getc_1 and
gdbsupport/format.h:format_piece::format_piece.
The above automatic change transformed
"gdb::to_string (const gdb::string_view &)" into
"gdb::to_string (const std::string_view &)". The various direct users
of this function are now explicitly including
"gdbsupport/gdb_string_view.h". A later patch will remove the users of
gdb::to_string.
The implementation and tests of gdb::string_view are unchanged, they will
be removed in a following patch.
Change-Id: Ibb806a7e9c79eb16a55c87c6e41ad396fecf0207
Approved-By: Tom Tromey <tom@tromey.com>
Approved-By: Pedro Alves <pedro@palves.net>
Diffstat (limited to 'gdbsupport')
-rw-r--r-- | gdbsupport/common-utils.h | 8 | ||||
-rw-r--r-- | gdbsupport/format.h | 5 | ||||
-rw-r--r-- | gdbsupport/gdb_string_view.h | 2 |
3 files changed, 8 insertions, 7 deletions
diff --git a/gdbsupport/common-utils.h b/gdbsupport/common-utils.h index 4ceb44d..1efc5bb 100644 --- a/gdbsupport/common-utils.h +++ b/gdbsupport/common-utils.h @@ -26,7 +26,7 @@ #include "gdbsupport/gdb_unique_ptr.h" #include "gdbsupport/array-view.h" #include "poison.h" -#include "gdb_string_view.h" +#include <string_view> #if defined HAVE_LIBXXHASH # include <xxhash.h> @@ -94,7 +94,7 @@ extern const char *safe_strerror (int); true if the start of STRING matches PATTERN, false otherwise. */ static inline bool -startswith (gdb::string_view string, gdb::string_view pattern) +startswith (std::string_view string, std::string_view pattern) { return (string.length () >= pattern.length () && strncmp (string.data (), pattern.data (), pattern.length ()) == 0); @@ -228,7 +228,7 @@ fast_hash (const void *ptr, size_t len, unsigned int start_value = 0) namespace gdb { -/* Hash type for gdb::string_view. +/* Hash type for std::string_view. Even after we switch to C++17 and dump our string_view implementation, we might want to keep this hash implementation if it's faster than std::hash @@ -236,7 +236,7 @@ namespace gdb struct string_view_hash { - std::size_t operator() (gdb::string_view view) const + std::size_t operator() (std::string_view view) const { return fast_hash (view.data (), view.length ()); } }; diff --git a/gdbsupport/format.h b/gdbsupport/format.h index 2af34ab..26e327a 100644 --- a/gdbsupport/format.h +++ b/gdbsupport/format.h @@ -20,7 +20,7 @@ #ifndef COMMON_FORMAT_H #define COMMON_FORMAT_H -#include "gdbsupport/gdb_string_view.h" +#include <string_view> #if defined(__MINGW32__) && !defined(PRINTF_HAS_LONG_LONG) # define USE_PRINTF_I64 1 @@ -56,12 +56,13 @@ struct format_piece argclass (argc), n_int_args (n) { + gdb_assert (str != nullptr); } bool operator== (const format_piece &other) const { return (this->argclass == other.argclass - && gdb::string_view (this->string) == other.string); + && std::string_view (this->string) == other.string); } const char *string; diff --git a/gdbsupport/gdb_string_view.h b/gdbsupport/gdb_string_view.h index 26a3a9f..cf7af62 100644 --- a/gdbsupport/gdb_string_view.h +++ b/gdbsupport/gdb_string_view.h @@ -556,7 +556,7 @@ namespace gdb { namespace gdb { static inline std::string -to_string(const gdb::string_view &view) +to_string(const std::string_view &view) { return { view.data (), view.size () }; } |