diff options
author | Pedro Alves <palves@redhat.com> | 2017-07-20 18:28:01 +0100 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2017-07-20 18:28:01 +0100 |
commit | 47e77640be31fc1a4eb3718f594ed5fd0faff065 (patch) | |
tree | fa4da7b4af36ba02faeb90cc9d5b554632a64797 /gdb/c-lang.c | |
parent | edb0c9cb22e5be90a76b8698b45e9eaee596f315 (diff) | |
download | binutils-47e77640be31fc1a4eb3718f594ed5fd0faff065.zip binutils-47e77640be31fc1a4eb3718f594ed5fd0faff065.tar.gz binutils-47e77640be31fc1a4eb3718f594ed5fd0faff065.tar.bz2 |
Make language_def O(1)
Profiling GDB with the rest of series applied, I saw calls to
language_def showing up high in some runs. The problem is that
language_def is O(N) currently, since walk the languages vector each
time to find the matching language_defn.
IMO, the add_language mechanism is pointless, because "enum language"
implies the core of GDB needs to know about all languages anyway. So
simply make the languages vector array be an array where each
element's index is the corresponding enum language enumerator. Note
that "local_language_defn" is gone along the way. It's just a copy of
"auto", so the new code simply maps one to the other. One fewer place
to update when we need to change the language vector...
Also, a while ago the output of "set language" was made out of order
as side effect of some other change. While I was at it, I made them
sorted again.
gdb/ChangeLog:
2017-07-20 Pedro Alves <palves@redhat.com>
* ada-lang.c (ada_language_defn): Make extern.
(_initialize_ada_language): Remove add_language call.
* c-lang.c (c_language_defn, cplus_language_defn)
(asm_language_defn, minimal_language_defn): Make extern.
(_initialize_c_language): Delete.
* completer.c (compare_cstrings): Delete, moved to utils.h.
* d-lang.c (d_language_defn): Make extern.
(_initialize_d_language): Remove add_language calls.
* defs.h (enum language): Add comment.
* f-lang.c (f_language_defn): Make extern.
(_initialize_f_language): Remove add_language call.
* go-lang.c (go_language_defn): Make extern.
(_initialize_go_language): Remove add_language call.
* language.c: Include <algorithm>.
(languages): Redefine as const array.
(languages_size, languages_allocsize, DEFAULT_ALLOCSIZE): Delete.
(set_language_command): Handle "local". Use for-range loop.
(set_language): Remove loop.
(language_enum): Rewrite.
(language_def, language_str): Remove loops.
(add_language): Delete.
(add_set_language_command): New, based on add_languages.
(skip_language_trampoline): Adjust.
(local_language_defn): Delete.
(language_gdbarch_post_init): Adjust.
(_initialize_language): Remove add_language calls. Call
add_set_language_command.
* language.h (add_language): Delete.
(auto_language_defn)
(unknown_language_defn, minimal_language_defn, ada_language_defn)
(asm_language_defn, c_language_defn, cplus_language_defn)
(d_language_defn, f_language_defn, go_language_defn)
(m2_language_defn, objc_language_defn, opencl_language_defn)
(pascal_language_defn, rust_language_defn): Declare.
* m2-lang.c (m2_language_defn): Make extern.
(_initialize_m2_language): Remove add_language call.
* objc-lang.c (objc_language_defn): Make extern.
(_initialize_objc_language): Remove add_language call.
* opencl-lang.c (opencl_language_defn): Make extern.
(_initialize_opencl_language): Remove add_language call.
* p-lang.c (pascal_language_defn): Make extern.
(_initialize_pascal_language): Delete.
* rust-lang.c (rust_language_defn): Make extern.
(_initialize_rust_language): Delete.
* utils.h (compare_cstrings): New static inline function.
gdb/testsuite/ChangeLog:
2017-07-20 Pedro Alves <palves@redhat.com>
* gdb.base/default.exp (set language): Adjust expected output.
Diffstat (limited to 'gdb/c-lang.c')
-rw-r--r-- | gdb/c-lang.c | 19 |
1 files changed, 4 insertions, 15 deletions
diff --git a/gdb/c-lang.c b/gdb/c-lang.c index 695b237..f86e26e 100644 --- a/gdb/c-lang.c +++ b/gdb/c-lang.c @@ -35,8 +35,6 @@ #include <ctype.h> #include "gdbcore.h" -extern void _initialize_c_language (void); - /* Given a C string type, STR_TYPE, return the corresponding target character set name. */ @@ -831,7 +829,7 @@ static const char *c_extensions[] = ".c", NULL }; -const struct language_defn c_language_defn = +extern const struct language_defn c_language_defn = { "c", /* Language name */ "C", @@ -975,7 +973,7 @@ static const char *cplus_extensions[] = ".C", ".cc", ".cp", ".cpp", ".cxx", ".c++", NULL }; -const struct language_defn cplus_language_defn = +extern const struct language_defn cplus_language_defn = { "c++", /* Language name */ "C++", @@ -1028,7 +1026,7 @@ static const char *asm_extensions[] = ".s", ".sx", ".S", NULL }; -const struct language_defn asm_language_defn = +extern const struct language_defn asm_language_defn = { "asm", /* Language name */ "assembly", @@ -1081,7 +1079,7 @@ const struct language_defn asm_language_defn = to do some simple operations when debugging applications that use a language currently not supported by GDB. */ -const struct language_defn minimal_language_defn = +extern const struct language_defn minimal_language_defn = { "minimal", /* Language name */ "Minimal", @@ -1128,12 +1126,3 @@ const struct language_defn minimal_language_defn = NULL, LANG_MAGIC }; - -void -_initialize_c_language (void) -{ - add_language (&c_language_defn); - add_language (&cplus_language_defn); - add_language (&asm_language_defn); - add_language (&minimal_language_defn); -} |