From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 5/5] Remove another redundant variable from array_operation::evaluate
Date: Mon, 28 Aug 2023 13:59:35 -0600 [thread overview]
Message-ID: <20230828-cleanup-array-op-v1-5-12ca00f20917@adacore.com> (raw)
In-Reply-To: <20230828-cleanup-array-op-v1-0-12ca00f20917@adacore.com>
This removes yet another redundant variable from
array_operation::evaluate -- only one index is needed.
---
gdb/eval.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/gdb/eval.c b/gdb/eval.c
index 710506ef778..8dd1b530d06 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -2419,7 +2419,7 @@ array_operation::evaluate (struct type *expect_type,
struct type *element_type = type->target_type ();
struct value *array = value::allocate (expect_type);
int element_size = check_typedef (element_type)->length ();
- LONGEST low_bound, high_bound, index;
+ LONGEST low_bound, high_bound;
if (!get_discrete_bounds (range_type, &low_bound, &high_bound))
{
@@ -2428,21 +2428,17 @@ array_operation::evaluate (struct type *expect_type,
}
if (low_bound + nargs - 1 > high_bound)
error (_("Too many array elements"));
- index = low_bound;
memset (array->contents_raw ().data (), 0, expect_type->length ());
- for (int tem = 0; tem < nargs; ++tem)
+ for (int idx = 0; idx < nargs; ++idx)
{
struct value *element;
- element = in_args[index - low_bound]->evaluate (element_type,
- exp, noside);
+ element = in_args[idx]->evaluate (element_type, exp, noside);
if (element->type () != element_type)
element = value_cast (element_type, element);
- memcpy (array->contents_raw ().data ()
- + (index - low_bound) * element_size,
+ memcpy (array->contents_raw ().data () + idx * element_size,
element->contents ().data (),
element_size);
- index++;
}
return array;
}
--
2.40.1
next prev parent reply other threads:[~2023-08-28 19:59 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-28 19:59 [PATCH 0/5] Small cleanups in array_operation::evaluate Tom Tromey
2023-08-28 19:59 ` [PATCH 1/5] Use gdb::array_view for value_array Tom Tromey
2023-08-28 21:10 ` Simon Marchi
2023-08-29 15:13 ` Tom Tromey
2023-08-28 19:59 ` [PATCH 2/5] Declare 'tem' in loop header in array_operation::evaluate Tom Tromey
2023-08-28 19:59 ` [PATCH 3/5] Hoist array bounds check " Tom Tromey
2023-08-28 19:59 ` [PATCH 4/5] Remove redundant variable from array_operation::evaluate Tom Tromey
2023-08-28 19:59 ` Tom Tromey [this message]
2023-08-28 21:12 ` [PATCH 0/5] Small cleanups in array_operation::evaluate John Baldwin
2023-08-29 15:35 ` Tom Tromey
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=20230828-cleanup-array-op-v1-5-12ca00f20917@adacore.com \
--to=tromey@adacore.com \
--cc=gdb-patches@sourceware.org \
/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).