From: Simon Marchi <simark@simark.ca>
To: Tom Tromey <tromey@adacore.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH 2/2] Use obstack in ada_encode_1
Date: Fri, 2 Oct 2020 17:54:00 -0400 [thread overview]
Message-ID: <2d52a731-17e4-4a8f-0916-9a2203b0c94d@simark.ca> (raw)
In-Reply-To: <20201002202604.1517475-3-tromey@adacore.com>
On 2020-10-02 4:26 p.m., Tom Tromey wrote:
> I'd eventually like to get rid of the GROW_VECT macro; and since I had
> already touched ada_encode_1 I decided to start here. This patch
> removes the use of the macro in favor of using an obstack in this
> function.
>
> 2020-10-02 Tom Tromey <tromey@adacore.com>
>
> * ada-lang.c (ada_encode_1): Use an obstack.
> ---
> gdb/ChangeLog | 4 ++++
> gdb/ada-lang.c | 26 +++++++-------------------
> 2 files changed, 11 insertions(+), 19 deletions(-)
>
> diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
> index 2502d2847b2..dfe9d44959f 100644
> --- a/gdb/ada-lang.c
> +++ b/gdb/ada-lang.c
> @@ -926,25 +926,17 @@ const struct ada_opname_map ada_opname_table[] = {
> static const char *
> ada_encode_1 (const char *decoded, bool throw_errors)
> {
> - static char *encoding_buffer = NULL;
> - static size_t encoding_buffer_size = 0;
> + static auto_obstack encoding_buffer;
> const char *p;
> - int k;
>
> if (decoded == NULL)
> return NULL;
>
> - GROW_VECT (encoding_buffer, encoding_buffer_size,
> - 2 * strlen (decoded) + 10);
> -
> - k = 0;
> + encoding_buffer.clear ();
> for (p = decoded; *p != '\0'; p += 1)
> {
> if (*p == '.')
> - {
> - encoding_buffer[k] = encoding_buffer[k + 1] = '_';
> - k += 2;
> - }
> + obstack_grow_str (&encoding_buffer, "__");
> else if (*p == '"')
> {
> const struct ada_opname_map *mapping;
> @@ -960,19 +952,15 @@ ada_encode_1 (const char *decoded, bool throw_errors)
> else
> return NULL;
> }
> - strcpy (encoding_buffer + k, mapping->encoded);
> - k += strlen (mapping->encoded);
> + obstack_grow_str (&encoding_buffer, mapping->encoded);
> break;
> }
> else
> - {
> - encoding_buffer[k] = *p;
> - k += 1;
> - }
> + obstack_1grow (&encoding_buffer, *p);
> }
>
> - encoding_buffer[k] = '\0';
> - return encoding_buffer;
> + obstack_1grow (&encoding_buffer, '\0');
> + return (const char *) obstack_finish (&encoding_buffer);
> }
>
> /* The "encoded" form of DECODED, according to GNAT conventions.
> --
> 2.26.2
>
I think the same could be achieved using a static std::string instead of
an obstack, and it would be a bit more C++-y, but either way is fine
with me.
Simon
next prev parent reply other threads:[~2020-10-02 21:54 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-02 20:26 [PATCH 0/2] ada_encode rewrites Tom Tromey
2020-10-02 20:26 ` [PATCH 1/2] Constify ada_encode return type Tom Tromey
2020-10-02 21:51 ` Simon Marchi
2020-10-07 18:26 ` Tom Tromey
2020-10-02 20:26 ` [PATCH 2/2] Use obstack in ada_encode_1 Tom Tromey
2020-10-02 21:54 ` Simon Marchi [this message]
2020-10-07 18:35 ` Tom Tromey
2020-10-07 18:36 ` Simon Marchi
2020-10-09 20:14 ` Joel Brobecker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2d52a731-17e4-4a8f-0916-9a2203b0c94d@simark.ca \
--to=simark@simark.ca \
--cc=gdb-patches@sourceware.org \
--cc=tromey@adacore.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).