aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2019-06-18 12:18:24 -0600
committerTom Tromey <tromey@adacore.com>2019-06-19 05:34:51 -0600
commitdcf3792354ddcd6e10e59e32060e34b27246e7da (patch)
tree4f448b277584ac9c09a49cfd242dffcf2e39ae65
parent6f5601c4d0ad43254244f1b624900cdd5afd02ba (diff)
downloadgdb-dcf3792354ddcd6e10e59e32060e34b27246e7da.zip
gdb-dcf3792354ddcd6e10e59e32060e34b27246e7da.tar.gz
gdb-dcf3792354ddcd6e10e59e32060e34b27246e7da.tar.bz2
Instantiate a single source highlighter
It occurred to me that there's no reason to make a new source highlighter each time gdb needs to highlight some source code. Instead, a single one can be created and then simply reused each time. This patch implements this idea. Tested on x86-64 Fedora 29. gdb/ChangeLog 2019-06-19 Tom Tromey <tromey@adacore.com> * source-cache.c (highlighter): New global. (source_cache::get_source_lines): Create a highlighter on demand.
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/source-cache.c17
2 files changed, 19 insertions, 3 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index a2abef1..5565097 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2019-06-19 Tom Tromey <tromey@adacore.com>
+
+ * source-cache.c (highlighter): New global.
+ (source_cache::get_source_lines): Create a highlighter on demand.
+
2019-06-18 Andrew Burgess <andrew.burgess@embecosm.com>
* defs.h (deprecated_interactive_hook): Delete declaration.
diff --git a/gdb/source-cache.c b/gdb/source-cache.c
index 2d5b549..86efe83 100644
--- a/gdb/source-cache.c
+++ b/gdb/source-cache.c
@@ -197,6 +197,13 @@ source_cache::get_source_lines (struct symtab *s, int first_line,
std::ifstream input (fullname);
if (input.is_open ())
{
+ /* The global source highlight object, or null if one
+ was never constructed. This is stored here rather
+ than in the class so that we don't need to include
+ anything or do conditional compilation in
+ source-cache.h. */
+ static srchilite::SourceHighlight *highlighter;
+
if (s->line_charpos == 0)
{
scoped_fd desc (open_source_file_with_line_charpos (s));
@@ -209,11 +216,15 @@ source_cache::get_source_lines (struct symtab *s, int first_line,
use-after-free. */
fullname = symtab_to_fullname (s);
}
- srchilite::SourceHighlight highlighter ("esc.outlang");
- highlighter.setStyleFile("esc.style");
+
+ if (highlighter == nullptr)
+ {
+ highlighter = new srchilite::SourceHighlight ("esc.outlang");
+ highlighter->setStyleFile ("esc.style");
+ }
std::ostringstream output;
- highlighter.highlight (input, output, lang_name, fullname);
+ highlighter->highlight (input, output, lang_name, fullname);
source_text result = { fullname, output.str () };
m_source_map.push_back (std::move (result));