From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32189 invoked by alias); 18 Jun 2019 19:40:59 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 32179 invoked by uid 89); 18 Jun 2019 19:40:58 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.8 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy=HContent-Transfer-Encoding:8bit X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 18 Jun 2019 19:40:57 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id C19F956084; Tue, 18 Jun 2019 15:40:55 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id BN5syzvjgXjn; Tue, 18 Jun 2019 15:40:55 -0400 (EDT) Received: from murgatroyd.Home (75-166-12-78.hlrn.qwest.net [75.166.12.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id 6C39F56062; Tue, 18 Jun 2019 15:40:55 -0400 (EDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Instantiate a single source highlighter Date: Tue, 18 Jun 2019 19:40:00 -0000 Message-Id: <20190618194053.7515-1-tromey@adacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SW-Source: 2019-06/txt/msg00353.txt.bz2 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-18 Tom Tromey * source-cache.c (highlighter): New global. (source_cache::get_source_lines): Create a highlighter on demand. --- gdb/ChangeLog | 5 +++++ gdb/source-cache.c | 19 ++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/gdb/source-cache.c b/gdb/source-cache.c index 2d5b549d971..0fa456116b4 100644 --- a/gdb/source-cache.c +++ b/gdb/source-cache.c @@ -33,6 +33,7 @@ #include #include #include +#include #endif /* The number of source files we'll cache. */ @@ -43,6 +44,14 @@ source_cache g_source_cache; +/* 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. */ +#ifdef HAVE_SOURCE_HIGHLIGHT +static srchilite::SourceHighlight *highlighter; +#endif + /* See source-cache.h. */ bool @@ -209,11 +218,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)); -- 2.20.1